2013-12-15 11:10:32 -05:00
|
|
|
/*
|
|
|
|
* commands.c
|
|
|
|
*
|
2015-02-10 18:16:09 -05:00
|
|
|
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
|
2013-12-15 11:10:32 -05:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
2014-08-24 15:57:39 -04:00
|
|
|
* 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.
|
|
|
|
*
|
2013-12-15 11:10:32 -05:00
|
|
|
*/
|
|
|
|
|
2014-05-19 16:25:21 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2014-12-21 19:01:43 -05:00
|
|
|
#include <assert.h>
|
2013-12-15 11:10:32 -05:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "chat_session.h"
|
|
|
|
#include "command/commands.h"
|
2014-01-23 18:53:20 -05:00
|
|
|
#include "command/command.h"
|
2013-12-15 11:10:32 -05:00
|
|
|
#include "common.h"
|
|
|
|
#include "config/accounts.h"
|
2014-01-22 17:22:01 -05:00
|
|
|
#include "config/account.h"
|
2013-12-15 11:10:32 -05:00
|
|
|
#include "config/preferences.h"
|
|
|
|
#include "config/theme.h"
|
2015-09-23 19:43:41 -04:00
|
|
|
#include "config/tlscerts.h"
|
2015-10-15 18:57:52 -04:00
|
|
|
#include "config/scripts.h"
|
2013-12-15 11:10:32 -05:00
|
|
|
#include "contact.h"
|
|
|
|
#include "roster_list.h"
|
|
|
|
#include "jid.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "muc.h"
|
2014-05-19 15:41:19 -04:00
|
|
|
#ifdef HAVE_LIBOTR
|
2014-02-12 17:19:21 -05:00
|
|
|
#include "otr/otr.h"
|
2014-05-19 15:41:19 -04:00
|
|
|
#endif
|
2015-03-21 20:12:14 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
|
|
|
#include "pgp/gpg.h"
|
|
|
|
#endif
|
2013-12-15 11:10:32 -05:00
|
|
|
#include "profanity.h"
|
|
|
|
#include "tools/autocomplete.h"
|
|
|
|
#include "tools/parser.h"
|
|
|
|
#include "tools/tinyurl.h"
|
|
|
|
#include "xmpp/xmpp.h"
|
|
|
|
#include "xmpp/bookmark.h"
|
2014-04-06 16:35:17 -04:00
|
|
|
#include "ui/ui.h"
|
2015-06-15 14:26:28 -04:00
|
|
|
#include "window_list.h"
|
2015-04-19 14:40:15 -04:00
|
|
|
#include "event/client_events.h"
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
static void _update_presence(const resource_presence_t presence,
|
2015-10-24 19:31:42 -04:00
|
|
|
const char *const show, gchar **args);
|
|
|
|
static gboolean _cmd_set_boolean_preference(gchar *arg, const char *const command,
|
|
|
|
const char *const display, preference_t pref);
|
|
|
|
static void _who_room(ProfWin *window, const char *const command, gchar **args);
|
|
|
|
static void _who_roster(ProfWin *window, const char *const command, gchar **args);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
extern GHashTable *commands;
|
|
|
|
|
2015-03-15 20:03:07 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_execute_default(ProfWin *window, const char *inp)
|
2015-03-15 20:03:07 -04:00
|
|
|
{
|
|
|
|
// handle escaped commands - treat as normal message
|
|
|
|
if (g_str_has_prefix(inp, "//")) {
|
|
|
|
inp++;
|
|
|
|
|
|
|
|
// handle unknown commands
|
|
|
|
} else if ((inp[0] == '/') && (!g_str_has_prefix(inp, "/me "))) {
|
|
|
|
cons_show("Unknown command: %s", inp);
|
|
|
|
cons_alert();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-21 16:57:39 -04:00
|
|
|
// handle non commands in non chat windows
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE) {
|
2015-04-21 16:57:39 -04:00
|
|
|
cons_show("Unknown command: %s", inp);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-03-15 20:03:07 -04:00
|
|
|
|
2015-04-21 16:57:39 -04:00
|
|
|
jabber_conn_status_t status = jabber_get_connection_status();
|
|
|
|
if (status != JABBER_CONNECTED) {
|
|
|
|
ui_current_print_line("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-03-15 20:03:07 -04:00
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
switch (window->type) {
|
2015-04-21 16:57:39 -04:00
|
|
|
case WIN_CHAT:
|
|
|
|
{
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-04-29 17:59:44 -04:00
|
|
|
cl_ev_send_msg(chatwin, inp);
|
2015-04-21 16:57:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIN_PRIVATE:
|
|
|
|
{
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
|
|
|
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
2015-05-03 20:31:27 -04:00
|
|
|
cl_ev_send_priv_msg(privatewin, inp);
|
2015-04-21 16:57:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIN_MUC:
|
|
|
|
{
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2015-05-03 20:06:12 -04:00
|
|
|
cl_ev_send_muc_msg(mucwin, inp);
|
2015-04-21 16:57:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2015-03-15 20:03:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran)
|
2015-03-15 20:03:07 -04:00
|
|
|
{
|
|
|
|
if (inp[0] != '/') {
|
|
|
|
ran = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-04-21 18:45:03 -04:00
|
|
|
|
|
|
|
char *alias = strdup(inp+1);
|
|
|
|
char *value = prefs_get_alias(alias);
|
|
|
|
free(alias);
|
|
|
|
if (value) {
|
|
|
|
*ran = TRUE;
|
2015-06-16 17:59:08 -04:00
|
|
|
return cmd_process_input(window, value);
|
2015-04-21 18:45:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*ran = FALSE;
|
|
|
|
return TRUE;
|
2015-03-15 20:03:07 -04:00
|
|
|
}
|
|
|
|
|
2015-09-22 16:42:05 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_tls(ProfWin *window, const char *const command, gchar **args)
|
2015-09-22 16:42:05 -04:00
|
|
|
{
|
2015-09-23 15:37:41 -04:00
|
|
|
if (g_strcmp0(args[0], "certpath") == 0) {
|
2015-11-09 18:31:21 -05:00
|
|
|
#ifdef HAVE_LIBMESODE
|
2015-09-23 15:37:41 -04:00
|
|
|
if (g_strcmp0(args[1], "set") == 0) {
|
|
|
|
if (args[2] == NULL) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-09-23 15:42:47 -04:00
|
|
|
|
|
|
|
if (g_file_test(args[2], G_FILE_TEST_IS_DIR)) {
|
2015-10-17 19:03:15 -04:00
|
|
|
prefs_set_string(PREF_TLS_CERTPATH, args[2]);
|
2015-09-23 15:42:47 -04:00
|
|
|
cons_show("Certificate path set to: %s", args[2]);
|
|
|
|
} else {
|
|
|
|
cons_show("Directory %s does not exist.", args[2]);
|
|
|
|
}
|
2015-09-23 15:37:41 -04:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "clear") == 0) {
|
2015-10-17 19:03:15 -04:00
|
|
|
prefs_set_string(PREF_TLS_CERTPATH, NULL);
|
2015-09-23 15:37:41 -04:00
|
|
|
cons_show("Certificate path cleared");
|
|
|
|
return TRUE;
|
|
|
|
} else if (args[1] == NULL) {
|
2015-10-17 19:03:15 -04:00
|
|
|
char *path = prefs_get_string(PREF_TLS_CERTPATH);
|
2015-09-23 15:37:41 -04:00
|
|
|
if (path) {
|
|
|
|
cons_show("Trusted certificate path: %s", path);
|
|
|
|
prefs_free_string(path);
|
|
|
|
} else {
|
|
|
|
cons_show("No trusted certificate path set.");
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-11-09 18:31:21 -05:00
|
|
|
#else
|
|
|
|
cons_show("Certificate path setting only supported when built with libmesode.");
|
2015-11-10 18:26:19 -05:00
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
} else if (g_strcmp0(args[0], "trust") == 0) {
|
|
|
|
#ifdef HAVE_LIBMESODE
|
2015-11-10 19:57:38 -05:00
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (!jabber_conn_is_secured()) {
|
|
|
|
cons_show("No TLS connection established");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-11-10 18:26:19 -05:00
|
|
|
TLSCertificate *cert = jabber_get_tls_peer_cert();
|
2015-11-10 19:57:38 -05:00
|
|
|
if (!cert) {
|
|
|
|
cons_show("Error getting TLS certificate.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (tlscerts_exists(cert->fingerprint)) {
|
2015-11-10 18:26:19 -05:00
|
|
|
cons_show("Certificate %s already trusted.", cert->fingerprint);
|
2015-11-10 19:57:38 -05:00
|
|
|
tlscerts_free(cert);
|
|
|
|
return TRUE;
|
2015-11-10 18:26:19 -05:00
|
|
|
}
|
2015-11-10 19:57:38 -05:00
|
|
|
cons_show("Adding %s to trusted certificates.", cert->fingerprint);
|
|
|
|
tlscerts_add(cert);
|
|
|
|
tlscerts_free(cert);
|
2015-11-10 18:26:19 -05:00
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
cons_show("Manual certificate trust only supported when built with libmesode.");
|
2015-11-09 18:31:21 -05:00
|
|
|
return TRUE;
|
|
|
|
#endif
|
2015-09-23 19:43:41 -04:00
|
|
|
} else if (g_strcmp0(args[0], "trusted") == 0) {
|
2015-11-09 18:31:21 -05:00
|
|
|
#ifdef HAVE_LIBMESODE
|
2015-09-23 19:43:41 -04:00
|
|
|
GList *certs = tlscerts_list();
|
|
|
|
GList *curr = certs;
|
|
|
|
|
|
|
|
if (curr) {
|
|
|
|
cons_show("Trusted certificates:");
|
|
|
|
cons_show("");
|
2015-09-23 20:06:53 -04:00
|
|
|
} else {
|
2015-10-25 21:07:15 -04:00
|
|
|
cons_show("No trusted certificates found.");
|
2015-09-23 19:43:41 -04:00
|
|
|
}
|
|
|
|
while (curr) {
|
|
|
|
TLSCertificate *cert = curr->data;
|
2015-11-09 20:20:40 -05:00
|
|
|
cons_show_tlscert(cert);
|
2015-09-23 19:43:41 -04:00
|
|
|
cons_show("");
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
g_list_free_full(certs, (GDestroyNotify)tlscerts_free);
|
|
|
|
return TRUE;
|
2015-11-09 18:31:21 -05:00
|
|
|
#else
|
|
|
|
cons_show("Manual certificate trust only supported when built with libmesode.");
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
2015-09-23 20:06:53 -04:00
|
|
|
} else if (g_strcmp0(args[0], "revoke") == 0) {
|
2015-11-09 18:31:21 -05:00
|
|
|
#ifdef HAVE_LIBMESODE
|
2015-09-23 20:06:53 -04:00
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else {
|
|
|
|
gboolean res = tlscerts_revoke(args[1]);
|
|
|
|
if (res) {
|
|
|
|
cons_show("Trusted certificate revoked: %s", args[1]);
|
|
|
|
} else {
|
|
|
|
cons_show("Could not find certificate: %s", args[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-11-09 18:31:21 -05:00
|
|
|
#else
|
|
|
|
cons_show("Manual certificate trust only supported when built with libmesode.");
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
2015-10-13 19:46:16 -04:00
|
|
|
} else if (g_strcmp0(args[0], "show") == 0) {
|
|
|
|
return _cmd_set_boolean_preference(args[1], command, "TLS titlebar indicator", PREF_TLS_SHOW);
|
2015-11-09 18:31:21 -05:00
|
|
|
} else if (g_strcmp0(args[0], "cert") == 0) {
|
|
|
|
#ifdef HAVE_LIBMESODE
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (!jabber_conn_is_secured()) {
|
|
|
|
cons_show("No TLS connection established");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-11-09 20:20:40 -05:00
|
|
|
TLSCertificate *cert = jabber_get_tls_peer_cert();
|
2015-11-10 19:57:38 -05:00
|
|
|
if (!cert) {
|
|
|
|
cons_show("Error getting TLS certificate.");
|
|
|
|
return TRUE;
|
2015-11-09 18:31:21 -05:00
|
|
|
}
|
2015-11-10 19:57:38 -05:00
|
|
|
cons_show_tlscert(cert);
|
|
|
|
cons_show("");
|
|
|
|
tlscerts_free(cert);
|
2015-11-09 18:31:21 -05:00
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
cons_show("Certificate fetching not supported.");
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
2015-09-23 15:37:41 -04:00
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-09-22 16:42:05 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_connect(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) {
|
2014-04-12 10:20:19 -04:00
|
|
|
cons_show("You are either connected already, or a login is in process.");
|
2015-04-21 19:29:37 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-04-14 18:15:39 -04:00
|
|
|
|
2015-10-17 22:06:23 -04:00
|
|
|
gchar *opt_keys[] = { "server", "port", "tls", NULL };
|
2015-04-21 19:29:37 -04:00
|
|
|
gboolean parsed;
|
2014-04-14 18:15:39 -04:00
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed);
|
|
|
|
if (!parsed) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-04-21 19:29:37 -04:00
|
|
|
cons_show("");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
char *altdomain = g_hash_table_lookup(options, "server");
|
2014-01-17 20:45:05 -05:00
|
|
|
|
2015-10-17 22:06:23 -04:00
|
|
|
char *tls_policy = g_hash_table_lookup(options, "tls");
|
|
|
|
if (tls_policy &&
|
|
|
|
(g_strcmp0(tls_policy, "force") != 0) &&
|
|
|
|
(g_strcmp0(tls_policy, "allow") != 0) &&
|
|
|
|
(g_strcmp0(tls_policy, "disable") != 0)) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
cons_show("");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
int port = 0;
|
|
|
|
if (g_hash_table_contains(options, "port")) {
|
|
|
|
char *port_str = g_hash_table_lookup(options, "port");
|
|
|
|
char *err_msg = NULL;
|
|
|
|
gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg);
|
|
|
|
if (!res) {
|
|
|
|
cons_show(err_msg);
|
|
|
|
cons_show("");
|
|
|
|
free(err_msg);
|
|
|
|
port = 0;
|
|
|
|
return TRUE;
|
2014-11-27 14:18:54 -05:00
|
|
|
}
|
2015-04-21 19:29:37 -04:00
|
|
|
}
|
2015-01-13 00:00:03 -05:00
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
char *user = args[0];
|
|
|
|
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
|
|
|
|
if (!user) {
|
|
|
|
if (def) {
|
|
|
|
user = def;
|
|
|
|
cons_show("Using default account %s.", user);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-04-21 19:29:37 -04:00
|
|
|
cons_show("No default account.");
|
|
|
|
g_free(def);
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2015-04-21 19:29:37 -04:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
char *lower = g_utf8_strdown(user, -1);
|
|
|
|
char *jid;
|
|
|
|
g_free(def);
|
2014-12-21 21:09:55 -05:00
|
|
|
|
2015-04-23 16:56:48 -04:00
|
|
|
// connect with account
|
2015-04-21 19:29:37 -04:00
|
|
|
ProfAccount *account = accounts_get_account(lower);
|
|
|
|
if (account) {
|
2015-04-23 16:56:48 -04:00
|
|
|
// use password if set
|
|
|
|
if (account->password) {
|
2015-04-28 18:38:56 -04:00
|
|
|
conn_status = cl_ev_connect_account(account);
|
2015-04-23 16:56:48 -04:00
|
|
|
|
|
|
|
// use eval_password if set
|
|
|
|
} else if (account->eval_password) {
|
|
|
|
gboolean res = account_eval_password(account);
|
|
|
|
if (res) {
|
2015-04-28 18:38:56 -04:00
|
|
|
conn_status = cl_ev_connect_account(account);
|
2015-04-23 16:56:48 -04:00
|
|
|
free(account->password);
|
|
|
|
account->password = NULL;
|
|
|
|
} else {
|
|
|
|
cons_show("Error evaluating password, see logs for details.");
|
|
|
|
g_free(lower);
|
2015-06-24 15:53:04 -04:00
|
|
|
account_free(account);
|
2015-04-23 16:56:48 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no account password setting, prompt
|
|
|
|
} else {
|
|
|
|
account->password = ui_ask_password();
|
2015-04-28 18:38:56 -04:00
|
|
|
conn_status = cl_ev_connect_account(account);
|
2015-04-23 16:56:48 -04:00
|
|
|
free(account->password);
|
|
|
|
account->password = NULL;
|
2015-04-21 19:29:37 -04:00
|
|
|
}
|
2015-04-23 16:56:48 -04:00
|
|
|
|
|
|
|
jid = account_create_full_jid(account);
|
2015-06-24 15:24:39 -04:00
|
|
|
account_free(account);
|
2015-04-23 16:56:48 -04:00
|
|
|
|
|
|
|
// connect with JID
|
2015-04-21 19:29:37 -04:00
|
|
|
} else {
|
|
|
|
jid = strdup(lower);
|
2015-04-23 16:56:48 -04:00
|
|
|
char *passwd = ui_ask_password();
|
2015-10-17 22:06:23 -04:00
|
|
|
conn_status = cl_ev_connect_jid(jid, passwd, altdomain, port, tls_policy);
|
2015-04-23 16:56:48 -04:00
|
|
|
free(passwd);
|
2015-04-21 19:29:37 -04:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
if (conn_status == JABBER_DISCONNECTED) {
|
|
|
|
cons_show_error("Connection attempt for %s failed.", jid);
|
|
|
|
log_info("Connection attempt for %s failed", jid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
2015-04-21 19:29:37 -04:00
|
|
|
options_destroy(options);
|
|
|
|
g_free(lower);
|
|
|
|
free(jid);
|
|
|
|
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_account(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
char *subcmd = args[0];
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
if (subcmd == NULL) {
|
2013-12-15 11:10:32 -05:00
|
|
|
if (jabber_get_connection_status() != JABBER_CONNECTED) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
ProfAccount *account = accounts_get_account(jabber_get_account_name());
|
|
|
|
cons_show_account(account);
|
2014-01-22 17:22:01 -05:00
|
|
|
account_free(account);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "list") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
gchar **accounts = accounts_get_list();
|
|
|
|
cons_show_account_list(accounts);
|
|
|
|
g_strfreev(accounts);
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "show") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
char *account_name = args[1];
|
|
|
|
if (account_name == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
ProfAccount *account = accounts_get_account(account_name);
|
|
|
|
if (account == NULL) {
|
|
|
|
cons_show("No such account.");
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
cons_show_account(account);
|
2014-01-22 17:22:01 -05:00
|
|
|
account_free(account);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "add") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
char *account_name = args[1];
|
|
|
|
if (account_name == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-10-17 22:06:23 -04:00
|
|
|
accounts_add(account_name, NULL, 0, NULL);
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Account created.");
|
|
|
|
cons_show("");
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "remove") == 0) {
|
2014-11-23 16:37:10 -05:00
|
|
|
char *account_name = args[1];
|
|
|
|
if(!account_name) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-23 16:37:10 -05:00
|
|
|
} else {
|
2014-11-27 21:26:10 -05:00
|
|
|
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
|
2014-11-23 16:37:10 -05:00
|
|
|
if(accounts_remove(account_name)){
|
|
|
|
cons_show("Account %s removed.", account_name);
|
2014-11-27 21:26:10 -05:00
|
|
|
if(def && strcmp(def, account_name) == 0){
|
|
|
|
prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL);
|
|
|
|
cons_show("Default account removed because the corresponding account was removed.");
|
|
|
|
}
|
2014-11-23 16:37:10 -05:00
|
|
|
} else {
|
|
|
|
cons_show("Failed to remove account %s.", account_name);
|
|
|
|
cons_show("Either the account does not exist, or an unknown error occurred.");
|
|
|
|
}
|
|
|
|
cons_show("");
|
2014-11-27 21:26:10 -05:00
|
|
|
g_free(def);
|
2014-11-23 16:37:10 -05:00
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "enable") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
char *account_name = args[1];
|
|
|
|
if (account_name == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
if (accounts_enable(account_name)) {
|
|
|
|
cons_show("Account enabled.");
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
cons_show("No such account: %s", account_name);
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "disable") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
char *account_name = args[1];
|
|
|
|
if (account_name == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
if (accounts_disable(account_name)) {
|
|
|
|
cons_show("Account disabled.");
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
cons_show("No such account: %s", account_name);
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "rename") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
if (g_strv_length(args) != 3) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
char *account_name = args[1];
|
|
|
|
char *new_name = args[2];
|
|
|
|
|
|
|
|
if (accounts_rename(account_name, new_name)) {
|
|
|
|
cons_show("Account renamed.");
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
cons_show("Either account %s doesn't exist, or account %s already exists.", account_name, new_name);
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "default") == 0) {
|
2014-11-27 12:42:23 -05:00
|
|
|
if(g_strv_length(args) == 1){
|
|
|
|
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
|
|
|
|
|
|
|
|
if(def){
|
|
|
|
cons_show("The default account is %s.", def);
|
|
|
|
free(def);
|
|
|
|
} else {
|
|
|
|
cons_show("No default account.");
|
|
|
|
}
|
|
|
|
} else if(g_strv_length(args) == 2){
|
|
|
|
if(strcmp(args[1], "off") == 0){
|
|
|
|
prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL);
|
|
|
|
cons_show("Removed default account.");
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-27 12:42:23 -05:00
|
|
|
}
|
|
|
|
} else if(g_strv_length(args) == 3) {
|
|
|
|
if(strcmp(args[1], "set") == 0){
|
|
|
|
if(accounts_get_account(args[2])){
|
|
|
|
prefs_set_string(PREF_DEFAULT_ACCOUNT, args[2]);
|
|
|
|
cons_show("Default account set to %s.", args[2]);
|
|
|
|
} else {
|
|
|
|
cons_show("Account %s does not exist.", args[2]);
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-27 12:42:23 -05:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-27 12:42:23 -05:00
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "set") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
if (g_strv_length(args) != 4) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
char *account_name = args[1];
|
|
|
|
char *property = args[2];
|
|
|
|
char *value = args[3];
|
|
|
|
|
|
|
|
if (!accounts_account_exists(account_name)) {
|
|
|
|
cons_show("Account %s doesn't exist", account_name);
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
if (strcmp(property, "jid") == 0) {
|
|
|
|
Jid *jid = jid_create(args[3]);
|
|
|
|
if (jid == NULL) {
|
|
|
|
cons_show("Malformed jid: %s", value);
|
|
|
|
} else {
|
|
|
|
accounts_set_jid(account_name, jid->barejid);
|
|
|
|
cons_show("Updated jid for account %s: %s", account_name, jid->barejid);
|
2015-05-04 17:23:59 -04:00
|
|
|
if (jid->resourcepart) {
|
2013-12-15 11:10:32 -05:00
|
|
|
accounts_set_resource(account_name, jid->resourcepart);
|
|
|
|
cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart);
|
|
|
|
}
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
jid_destroy(jid);
|
|
|
|
} else if (strcmp(property, "server") == 0) {
|
|
|
|
accounts_set_server(account_name, value);
|
|
|
|
cons_show("Updated server for account %s: %s", account_name, value);
|
|
|
|
cons_show("");
|
2014-01-18 19:05:04 -05:00
|
|
|
} else if (strcmp(property, "port") == 0) {
|
|
|
|
int port;
|
2015-03-15 21:03:20 -04:00
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &port, 1, 65535, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (!res) {
|
|
|
|
cons_show(err_msg);
|
2014-01-18 19:05:04 -05:00
|
|
|
cons_show("");
|
2015-03-15 21:03:20 -04:00
|
|
|
free(err_msg);
|
2014-01-18 19:05:04 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
accounts_set_port(account_name, port);
|
|
|
|
cons_show("Updated port for account %s: %s", account_name, value);
|
|
|
|
cons_show("");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else if (strcmp(property, "resource") == 0) {
|
|
|
|
accounts_set_resource(account_name, value);
|
2015-06-24 16:36:39 -04:00
|
|
|
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);
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("");
|
|
|
|
} else if (strcmp(property, "password") == 0) {
|
2015-05-04 17:23:59 -04:00
|
|
|
if(accounts_get_account(account_name)->eval_password) {
|
2015-01-07 00:00:02 -05:00
|
|
|
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) {
|
2015-05-04 17:23:59 -04:00
|
|
|
if(accounts_get_account(account_name)->password) {
|
2015-01-07 00:00:02 -05:00
|
|
|
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("");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} 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("");
|
2014-05-11 08:48:41 -04:00
|
|
|
} else if (strcmp(property, "otr") == 0) {
|
|
|
|
if ((g_strcmp0(value, "manual") != 0)
|
|
|
|
&& (g_strcmp0(value, "opportunistic") != 0)
|
|
|
|
&& (g_strcmp0(value, "always") != 0)) {
|
2014-05-11 09:13:15 -04:00
|
|
|
cons_show("OTR policy must be one of: manual, opportunistic or always.");
|
2014-05-11 08:48:41 -04:00
|
|
|
} else {
|
2014-05-11 09:13:15 -04:00
|
|
|
accounts_set_otr_policy(account_name, value);
|
2014-05-11 08:48:41 -04:00
|
|
|
cons_show("Updated OTR policy for account %s: %s", account_name, value);
|
|
|
|
cons_show("");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} 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("");
|
2015-03-23 19:38:06 -04:00
|
|
|
} else if (strcmp(property, "pgpkeyid") == 0) {
|
2015-08-25 15:35:45 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2015-08-23 18:05:39 -04:00
|
|
|
if (!p_gpg_valid_key(value)) {
|
|
|
|
cons_show("Invalid PGP key ID specified, see /pgp keys");
|
|
|
|
} else {
|
|
|
|
accounts_set_pgp_keyid(account_name, value);
|
|
|
|
cons_show("Updated PGP key ID for account %s: %s", account_name, value);
|
|
|
|
}
|
2015-08-25 15:35:45 -04:00
|
|
|
#else
|
|
|
|
cons_show("PGP support is not included in this build.");
|
|
|
|
#endif
|
2015-03-23 19:38:06 -04:00
|
|
|
cons_show("");
|
2015-10-14 20:19:24 -04:00
|
|
|
} 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);
|
2015-10-17 22:06:23 -04:00
|
|
|
} 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("");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else if (valid_resource_presence_string(property)) {
|
2015-03-15 21:03:20 -04:00
|
|
|
int intval;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
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;
|
|
|
|
}
|
2013-12-17 18:57:06 -05:00
|
|
|
|
2015-03-15 21:03:20 -04:00
|
|
|
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);
|
2013-12-17 18:57:06 -05:00
|
|
|
|
2015-03-15 21:03:20 -04:00
|
|
|
if (presence_type == last_presence) {
|
|
|
|
char *message = jabber_get_presence_message();
|
2015-05-07 18:21:48 -04:00
|
|
|
cl_ev_presence_send(last_presence, message, 0);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-15 21:03:20 -04:00
|
|
|
cons_show("Updated %s priority for account %s: %s", property, account_name, value);
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("Invalid property: %s", property);
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
} else if (strcmp(subcmd, "clear") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
if (g_strv_length(args) != 3) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
char *account_name = args[1];
|
|
|
|
char *property = args[2];
|
|
|
|
|
|
|
|
if (!accounts_account_exists(account_name)) {
|
|
|
|
cons_show("Account %s doesn't exist", account_name);
|
|
|
|
cons_show("");
|
|
|
|
} else {
|
|
|
|
if (strcmp(property, "password") == 0) {
|
|
|
|
accounts_clear_password(account_name);
|
|
|
|
cons_show("Removed password for account %s", account_name);
|
|
|
|
cons_show("");
|
2015-01-07 00:00:02 -05:00
|
|
|
} else if (strcmp(property, "eval_password") == 0) {
|
|
|
|
accounts_clear_eval_password(account_name);
|
|
|
|
cons_show("Removed eval password for account %s", account_name);
|
|
|
|
cons_show("");
|
2014-10-23 18:07:27 -04:00
|
|
|
} else if (strcmp(property, "server") == 0) {
|
|
|
|
accounts_clear_server(account_name);
|
|
|
|
cons_show("Removed server for account %s", account_name);
|
|
|
|
cons_show("");
|
2014-10-23 18:12:15 -04:00
|
|
|
} else if (strcmp(property, "port") == 0) {
|
|
|
|
accounts_clear_port(account_name);
|
|
|
|
cons_show("Removed port for account %s", account_name);
|
|
|
|
cons_show("");
|
2014-05-11 10:32:38 -04:00
|
|
|
} else if (strcmp(property, "otr") == 0) {
|
|
|
|
accounts_clear_otr(account_name);
|
|
|
|
cons_show("OTR policy removed for account %s", account_name);
|
|
|
|
cons_show("");
|
2015-03-23 19:38:06 -04:00
|
|
|
} else if (strcmp(property, "pgpkeyid") == 0) {
|
|
|
|
accounts_clear_pgp_keyid(account_name);
|
|
|
|
cons_show("Removed PGP key ID for account %s", account_name);
|
|
|
|
cons_show("");
|
2015-10-14 20:19:24 -04:00
|
|
|
} else if (strcmp(property, "startscript") == 0) {
|
|
|
|
accounts_clear_script_start(account_name);
|
|
|
|
cons_show("Removed start script for account %s", account_name);
|
|
|
|
cons_show("");
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("Invalid property: %s", property);
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-15 18:57:52 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_script(ProfWin *window, const char *const command, gchar **args)
|
2015-10-15 18:57:52 -04:00
|
|
|
{
|
|
|
|
if ((g_strcmp0(args[0], "run") == 0) && args[1]) {
|
|
|
|
gboolean res = scripts_exec(args[1]);
|
|
|
|
if (!res) {
|
|
|
|
cons_show("Could not find script %s", args[1]);
|
|
|
|
}
|
2015-10-17 17:30:01 -04:00
|
|
|
} else if (g_strcmp0(args[0], "list") == 0) {
|
|
|
|
GSList *scripts = scripts_list();
|
|
|
|
cons_show_scripts(scripts);
|
|
|
|
g_slist_free_full(scripts, g_free);
|
2015-10-17 17:58:45 -04:00
|
|
|
} else if ((g_strcmp0(args[0], "show") == 0) && args[1]) {
|
|
|
|
GSList *commands = scripts_read(args[1]);
|
|
|
|
cons_show_script(args[1], commands);
|
|
|
|
g_slist_free_full(commands, g_free);
|
2015-10-15 18:57:52 -04:00
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_sub(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are currently not connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *subcmd, *jid;
|
|
|
|
subcmd = args[0];
|
|
|
|
jid = args[1];
|
|
|
|
|
|
|
|
if (subcmd == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(subcmd, "sent") == 0) {
|
|
|
|
cons_show_sent_subs();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(subcmd, "received") == 0) {
|
|
|
|
cons_show_received_subs();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if ((window->type != WIN_CHAT) && (jid == NULL)) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("You must specify a contact.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jid == NULL) {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
jid = chatwin->barejid;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Jid *jidp = jid_create(jid);
|
|
|
|
|
|
|
|
if (strcmp(subcmd, "allow") == 0) {
|
|
|
|
presence_subscription(jidp->barejid, PRESENCE_SUBSCRIBED);
|
|
|
|
cons_show("Accepted subscription for %s", jidp->barejid);
|
|
|
|
log_info("Accepted subscription for %s", jidp->barejid);
|
|
|
|
} else if (strcmp(subcmd, "deny") == 0) {
|
|
|
|
presence_subscription(jidp->barejid, PRESENCE_UNSUBSCRIBED);
|
|
|
|
cons_show("Deleted/denied subscription for %s", jidp->barejid);
|
|
|
|
log_info("Deleted/denied subscription for %s", jidp->barejid);
|
|
|
|
} else if (strcmp(subcmd, "request") == 0) {
|
|
|
|
presence_subscription(jidp->barejid, PRESENCE_SUBSCRIBE);
|
|
|
|
cons_show("Sent subscription request to %s.", jidp->barejid);
|
|
|
|
log_info("Sent subscription request to %s.", jidp->barejid);
|
|
|
|
} else if (strcmp(subcmd, "show") == 0) {
|
|
|
|
PContact contact = roster_get_contact(jidp->barejid);
|
|
|
|
if ((contact == NULL) || (p_contact_subscription(contact) == NULL)) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type == WIN_CHAT) {
|
2013-12-15 11:10:32 -05:00
|
|
|
ui_current_print_line("No subscription information for %s.", jidp->barejid);
|
|
|
|
} else {
|
|
|
|
cons_show("No subscription information for %s.", jidp->barejid);
|
|
|
|
}
|
|
|
|
} else {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type == WIN_CHAT) {
|
2013-12-15 11:10:32 -05:00
|
|
|
if (p_contact_pending_out(contact)) {
|
|
|
|
ui_current_print_line("%s subscription status: %s, request pending.",
|
|
|
|
jidp->barejid, p_contact_subscription(contact));
|
|
|
|
} else {
|
|
|
|
ui_current_print_line("%s subscription status: %s.", jidp->barejid,
|
|
|
|
p_contact_subscription(contact));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p_contact_pending_out(contact)) {
|
|
|
|
cons_show("%s subscription status: %s, request pending.",
|
|
|
|
jidp->barejid, p_contact_subscription(contact));
|
|
|
|
} else {
|
|
|
|
cons_show("%s subscription status: %s.", jidp->barejid,
|
|
|
|
p_contact_subscription(contact));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
jid_destroy(jidp);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_disconnect(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
if (jabber_get_connection_status() == JABBER_CONNECTED) {
|
|
|
|
char *jid = strdup(jabber_get_fulljid());
|
2014-01-05 17:00:15 -05:00
|
|
|
cons_show("%s logged out successfully.", jid);
|
|
|
|
jabber_disconnect();
|
|
|
|
roster_clear();
|
2014-09-28 17:09:20 -04:00
|
|
|
muc_invites_clear();
|
2014-01-05 17:00:15 -05:00
|
|
|
chat_sessions_clear();
|
2015-11-09 15:57:26 -05:00
|
|
|
tlscerts_clear_current();
|
2014-01-05 17:00:15 -05:00
|
|
|
ui_disconnected();
|
2015-06-23 18:29:10 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
|
|
|
p_gpg_on_disconnect();
|
|
|
|
#endif
|
2013-12-15 11:10:32 -05:00
|
|
|
free(jid);
|
|
|
|
} else {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_quit(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
log_info("Profanity is shutting down...");
|
|
|
|
exit(0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_wins(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
if (args[0] == NULL) {
|
|
|
|
cons_show_wins();
|
|
|
|
} else if (strcmp(args[0], "tidy") == 0) {
|
2015-11-02 16:03:30 -05:00
|
|
|
if (wins_tidy()) {
|
2015-06-01 06:27:01 -04:00
|
|
|
cons_show("Windows tidied.");
|
|
|
|
} else {
|
|
|
|
cons_show("No tidy needed.");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else if (strcmp(args[0], "prune") == 0) {
|
|
|
|
ui_prune_wins();
|
2014-04-24 16:50:59 -04:00
|
|
|
} else if (strcmp(args[0], "swap") == 0) {
|
|
|
|
if ((args[1] == NULL) || (args[2] == NULL)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-24 16:50:59 -04:00
|
|
|
} else {
|
|
|
|
int source_win = atoi(args[1]);
|
|
|
|
int target_win = atoi(args[2]);
|
|
|
|
if ((source_win == 1) || (target_win == 1)) {
|
|
|
|
cons_show("Cannot move console window.");
|
2014-04-24 18:06:42 -04:00
|
|
|
} else if (source_win == 10 || target_win == 10) {
|
|
|
|
cons_show("Window 10 does not exist");
|
2014-04-24 16:50:59 -04:00
|
|
|
} else if (source_win != target_win) {
|
2015-11-02 16:05:21 -05:00
|
|
|
gboolean swapped = wins_swap(source_win, target_win);
|
2014-04-24 16:50:59 -04:00
|
|
|
if (swapped) {
|
|
|
|
cons_show("Swapped windows %d <-> %d", source_win, target_win);
|
|
|
|
} else {
|
|
|
|
cons_show("Window %d does not exist", source_win);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_show("Same source and target window supplied.");
|
|
|
|
}
|
|
|
|
}
|
2015-09-19 18:31:04 -04:00
|
|
|
} else if (strcmp(args[0], "autotidy") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "on") == 0) {
|
|
|
|
cons_show("Window autotidy enabled");
|
|
|
|
prefs_set_boolean(PREF_WINS_AUTO_TIDY, TRUE);
|
2015-11-02 16:03:30 -05:00
|
|
|
wins_tidy();
|
2015-09-19 18:31:04 -04:00
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
cons_show("Window autotidy disabled");
|
|
|
|
prefs_set_boolean(PREF_WINS_AUTO_TIDY, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
}
|
2015-07-25 21:09:01 -04:00
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2014-04-24 16:50:59 -04:00
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_win(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
int num = atoi(args[0]);
|
2015-04-30 17:09:39 -04:00
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
ProfWin *focuswin = wins_get_by_num(num);
|
|
|
|
if (!focuswin) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Window %d does not exist.", num);
|
2015-04-30 17:09:39 -04:00
|
|
|
} else {
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win(focuswin);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2015-04-30 17:09:39 -04:00
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:10:18 -04:00
|
|
|
static void
|
2015-10-24 19:31:42 -04:00
|
|
|
_cmd_help_cmd_list(const char *const tag)
|
2015-07-27 19:10:18 -04:00
|
|
|
{
|
|
|
|
cons_show("");
|
|
|
|
ProfWin *console = wins_get_console();
|
|
|
|
if (tag) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_vprint(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "%s commands", tag);
|
2015-07-27 19:10:18 -04:00
|
|
|
} else {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "All commands");
|
2015-07-27 19:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GList *ordered_commands = NULL;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key;
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
g_hash_table_iter_init(&iter, commands);
|
|
|
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
|
|
|
Command *pcmd = (Command *)value;
|
|
|
|
if (tag) {
|
|
|
|
if (cmd_has_tag(pcmd, tag)) {
|
|
|
|
ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int maxlen = 0;
|
|
|
|
GList *curr = ordered_commands;
|
|
|
|
while (curr) {
|
|
|
|
gchar *cmd = curr->data;
|
|
|
|
int len = strlen(cmd);
|
|
|
|
if (len > maxlen) maxlen = len;
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
GString *cmds = g_string_new("");
|
|
|
|
curr = ordered_commands;
|
|
|
|
int count = 0;
|
|
|
|
while (curr) {
|
|
|
|
gchar *cmd = curr->data;
|
|
|
|
if (count == 5) {
|
|
|
|
cons_show(cmds->str);
|
|
|
|
g_string_free(cmds, TRUE);
|
|
|
|
cmds = g_string_new("");
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd);
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
cons_show(cmds->str);
|
|
|
|
g_string_free(cmds, TRUE);
|
|
|
|
g_list_free(ordered_commands);
|
|
|
|
g_list_free(curr);
|
|
|
|
|
|
|
|
cons_show("");
|
|
|
|
cons_show("Use /help [command] without the leading slash, for help on a specific command");
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_help(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
int num_args = g_strv_length(args);
|
|
|
|
if (num_args == 0) {
|
|
|
|
cons_help();
|
|
|
|
} else if (strcmp(args[0], "commands") == 0) {
|
2015-07-27 18:55:04 -04:00
|
|
|
if (args[1]) {
|
|
|
|
if (!cmd_valid_tag(args[1])) {
|
|
|
|
cons_bad_cmd_usage(command);
|
2015-07-27 19:10:18 -04:00
|
|
|
} else {
|
|
|
|
_cmd_help_cmd_list(args[1]);
|
2015-07-27 18:55:04 -04:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-27 19:10:18 -04:00
|
|
|
_cmd_help_cmd_list(NULL);
|
2015-07-27 18:55:04 -04:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else if (strcmp(args[0], "navigation") == 0) {
|
|
|
|
cons_navigation_help();
|
|
|
|
} else {
|
|
|
|
char *cmd = args[0];
|
|
|
|
char cmd_with_slash[1 + strlen(cmd) + 1];
|
|
|
|
sprintf(cmd_with_slash, "/%s", cmd);
|
|
|
|
|
|
|
|
Command *command = g_hash_table_lookup(commands, cmd_with_slash);
|
2015-05-04 17:23:59 -04:00
|
|
|
if (command) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_show_help(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("No such command.");
|
|
|
|
}
|
|
|
|
cons_show("");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_about(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-10-26 16:37:50 -04:00
|
|
|
cons_show("");
|
|
|
|
cons_about();
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_prefs(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
if (args[0] == NULL) {
|
|
|
|
cons_prefs();
|
|
|
|
cons_show("Use the /account command for preferences for individual accounts.");
|
|
|
|
} else if (strcmp(args[0], "ui") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_ui_prefs();
|
|
|
|
cons_show("");
|
|
|
|
} else if (strcmp(args[0], "desktop") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_desktop_prefs();
|
|
|
|
cons_show("");
|
|
|
|
} else if (strcmp(args[0], "chat") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_chat_prefs();
|
|
|
|
cons_show("");
|
|
|
|
} else if (strcmp(args[0], "log") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_log_prefs();
|
|
|
|
cons_show("");
|
|
|
|
} else if (strcmp(args[0], "conn") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_connection_prefs();
|
|
|
|
cons_show("");
|
|
|
|
} else if (strcmp(args[0], "presence") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_presence_prefs();
|
|
|
|
cons_show("");
|
2014-05-11 08:32:59 -04:00
|
|
|
} else if (strcmp(args[0], "otr") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_otr_prefs();
|
|
|
|
cons_show("");
|
2015-06-22 16:09:14 -04:00
|
|
|
} else if (strcmp(args[0], "pgp") == 0) {
|
|
|
|
cons_show("");
|
|
|
|
cons_show_pgp_prefs();
|
|
|
|
cons_show("");
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_theme(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
// list themes
|
2014-11-17 16:10:08 -05:00
|
|
|
if (g_strcmp0(args[0], "list") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
GSList *themes = theme_list();
|
|
|
|
cons_show_themes(themes);
|
|
|
|
g_slist_free_full(themes, g_free);
|
|
|
|
|
|
|
|
// load a theme
|
2015-02-25 19:49:21 -05:00
|
|
|
} else if (g_strcmp0(args[0], "load") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
if (args[1] == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else if (theme_load(args[1])) {
|
|
|
|
ui_load_colours();
|
|
|
|
prefs_set_string(PREF_THEME, args[1]);
|
2014-11-19 18:58:55 -05:00
|
|
|
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();
|
|
|
|
}
|
2014-11-16 16:56:19 -05:00
|
|
|
ui_redraw();
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Loaded theme: %s", args[1]);
|
|
|
|
} else {
|
|
|
|
cons_show("Couldn't find theme: %s", args[1]);
|
|
|
|
}
|
2014-11-17 16:10:08 -05:00
|
|
|
|
|
|
|
// show colours
|
|
|
|
} else if (g_strcmp0(args[0], "colours") == 0) {
|
|
|
|
cons_theme_colours();
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-07-22 18:22:50 -04:00
|
|
|
static void
|
2015-10-24 19:31:42 -04:00
|
|
|
_who_room(ProfWin *window, const char *const command, gchar **args)
|
2014-07-22 18:22:50 -04:00
|
|
|
{
|
2015-05-04 17:23:59 -04:00
|
|
|
if ((g_strv_length(args) == 2) && args[1]) {
|
2014-10-04 16:53:04 -04:00
|
|
|
cons_show("Argument group is not applicable to chat rooms.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bad arg
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0] &&
|
2014-10-04 17:43:22 -04:00
|
|
|
(g_strcmp0(args[0], "online") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "available") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "unavailable") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "away") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "chat") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "xa") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "dnd") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "any") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "moderator") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "participant") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "visitor") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "owner") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "admin") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "member") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "outcast") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-04 16:53:04 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-07-22 18:22:50 -04:00
|
|
|
|
2014-10-04 17:43:22 -04:00
|
|
|
// presence filter
|
|
|
|
if (args[0] == NULL ||
|
|
|
|
(g_strcmp0(args[0], "online") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "available") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "unavailable") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "away") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "chat") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "xa") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "dnd") == 0) ||
|
|
|
|
(g_strcmp0(args[0], "any") == 0)) {
|
|
|
|
|
|
|
|
char *presence = args[0];
|
2014-12-18 18:57:19 -05:00
|
|
|
GList *occupants = muc_roster(mucwin->roomjid);
|
2014-10-04 17:43:22 -04:00
|
|
|
|
|
|
|
// no arg, show all contacts
|
|
|
|
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
|
2015-11-01 18:41:45 -05:00
|
|
|
mucwin_roster(mucwin, occupants, NULL);
|
2014-10-04 17:43:22 -04:00
|
|
|
|
|
|
|
// available
|
|
|
|
} else if (strcmp("available", presence) == 0) {
|
|
|
|
GList *filtered = NULL;
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
while (occupants) {
|
2014-11-03 16:27:41 -05:00
|
|
|
Occupant *occupant = occupants->data;
|
2014-10-04 17:43:22 -04:00
|
|
|
if (muc_occupant_available(occupant)) {
|
|
|
|
filtered = g_list_append(filtered, occupant);
|
|
|
|
}
|
2014-11-03 16:27:41 -05:00
|
|
|
occupants = g_list_next(occupants);
|
2014-10-04 17:43:22 -04:00
|
|
|
}
|
2014-07-22 18:22:50 -04:00
|
|
|
|
2015-11-01 18:41:45 -05:00
|
|
|
mucwin_roster(mucwin, filtered, "available");
|
2014-07-22 18:22:50 -04:00
|
|
|
|
2014-10-04 17:43:22 -04:00
|
|
|
// unavailable
|
|
|
|
} else if (strcmp("unavailable", presence) == 0) {
|
|
|
|
GList *filtered = NULL;
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
while (occupants) {
|
2014-11-03 16:27:41 -05:00
|
|
|
Occupant *occupant = occupants->data;
|
2014-10-04 17:43:22 -04:00
|
|
|
if (!muc_occupant_available(occupant)) {
|
|
|
|
filtered = g_list_append(filtered, occupant);
|
|
|
|
}
|
2014-11-03 16:27:41 -05:00
|
|
|
occupants = g_list_next(occupants);
|
2014-07-22 18:22:50 -04:00
|
|
|
}
|
|
|
|
|
2015-11-01 18:41:45 -05:00
|
|
|
mucwin_roster(mucwin, filtered, "unavailable");
|
2014-07-22 18:22:50 -04:00
|
|
|
|
2014-10-04 17:43:22 -04:00
|
|
|
// show specific status
|
|
|
|
} else {
|
|
|
|
GList *filtered = NULL;
|
2014-07-22 18:22:50 -04:00
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
while (occupants) {
|
2014-11-03 16:27:41 -05:00
|
|
|
Occupant *occupant = occupants->data;
|
2014-10-04 17:43:22 -04:00
|
|
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
|
|
|
if (strcmp(presence_str, presence) == 0) {
|
|
|
|
filtered = g_list_append(filtered, occupant);
|
|
|
|
}
|
2014-11-03 16:27:41 -05:00
|
|
|
occupants = g_list_next(occupants);
|
2014-07-22 18:22:50 -04:00
|
|
|
}
|
|
|
|
|
2015-11-01 18:41:45 -05:00
|
|
|
mucwin_roster(mucwin, filtered, presence);
|
2014-10-04 17:43:22 -04:00
|
|
|
}
|
2014-07-22 18:22:50 -04:00
|
|
|
|
2014-11-03 16:27:41 -05:00
|
|
|
g_list_free(occupants);
|
|
|
|
|
2014-10-04 17:43:22 -04:00
|
|
|
// role or affiliation filter
|
2014-07-22 18:22:50 -04:00
|
|
|
} else {
|
2014-10-04 17:43:22 -04:00
|
|
|
if (g_strcmp0(args[0], "moderator") == 0) {
|
2015-11-01 16:51:24 -05:00
|
|
|
mucwin_show_role_list(mucwin, MUC_ROLE_MODERATOR);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "participant") == 0) {
|
2015-11-01 16:51:24 -05:00
|
|
|
mucwin_show_role_list(mucwin, MUC_ROLE_PARTICIPANT);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "visitor") == 0) {
|
2015-11-01 16:51:24 -05:00
|
|
|
mucwin_show_role_list(mucwin, MUC_ROLE_VISITOR);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
2014-07-22 18:22:50 -04:00
|
|
|
}
|
|
|
|
|
2014-10-04 17:43:22 -04:00
|
|
|
if (g_strcmp0(args[0], "owner") == 0) {
|
2015-11-01 16:46:57 -05:00
|
|
|
mucwin_show_affiliation_list(mucwin, MUC_AFFILIATION_OWNER);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "admin") == 0) {
|
2015-11-01 16:46:57 -05:00
|
|
|
mucwin_show_affiliation_list(mucwin, MUC_AFFILIATION_ADMIN);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "member") == 0) {
|
2015-11-01 16:46:57 -05:00
|
|
|
mucwin_show_affiliation_list(mucwin, MUC_AFFILIATION_MEMBER);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "outcast") == 0) {
|
2015-11-01 16:46:57 -05:00
|
|
|
mucwin_show_affiliation_list(mucwin, MUC_AFFILIATION_OUTCAST);
|
2014-10-04 17:43:22 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-07-22 18:22:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 18:27:36 -04:00
|
|
|
static void
|
2015-10-24 19:31:42 -04:00
|
|
|
_who_roster(ProfWin *window, const char *const command, gchar **args)
|
2014-07-22 18:27:36 -04:00
|
|
|
{
|
2014-10-04 16:53:04 -04:00
|
|
|
char *presence = args[0];
|
|
|
|
|
|
|
|
// bad arg
|
2015-05-04 17:23:59 -04:00
|
|
|
if (presence
|
2014-10-04 16:53:04 -04:00
|
|
|
&& (strcmp(presence, "online") != 0)
|
|
|
|
&& (strcmp(presence, "available") != 0)
|
|
|
|
&& (strcmp(presence, "unavailable") != 0)
|
|
|
|
&& (strcmp(presence, "offline") != 0)
|
|
|
|
&& (strcmp(presence, "away") != 0)
|
|
|
|
&& (strcmp(presence, "chat") != 0)
|
|
|
|
&& (strcmp(presence, "xa") != 0)
|
|
|
|
&& (strcmp(presence, "dnd") != 0)
|
|
|
|
&& (strcmp(presence, "any") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-04 16:53:04 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *group = NULL;
|
2015-05-04 17:23:59 -04:00
|
|
|
if ((g_strv_length(args) == 2) && args[1]) {
|
2014-10-04 16:53:04 -04:00
|
|
|
group = args[1];
|
|
|
|
}
|
|
|
|
|
2014-07-22 18:27:36 -04:00
|
|
|
cons_show("");
|
|
|
|
GSList *list = NULL;
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2015-11-17 19:25:35 -05:00
|
|
|
list = roster_get_group(group, ROSTER_ORD_NAME, TRUE);
|
2014-07-22 18:31:14 -04:00
|
|
|
if (list == NULL) {
|
|
|
|
cons_show("No such group: %s.", group);
|
|
|
|
return;
|
|
|
|
}
|
2014-07-22 18:27:36 -04:00
|
|
|
} else {
|
2015-11-17 20:03:35 -05:00
|
|
|
list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
2014-07-22 18:31:14 -04:00
|
|
|
if (list == NULL) {
|
|
|
|
cons_show("No contacts in roster.");
|
|
|
|
return;
|
|
|
|
}
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// no arg, show all contacts
|
|
|
|
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2014-07-22 18:27:36 -04:00
|
|
|
if (list == NULL) {
|
|
|
|
cons_show("No contacts in group %s.", group);
|
|
|
|
} else {
|
|
|
|
cons_show("%s:", group);
|
|
|
|
cons_show_contacts(list);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (list == NULL) {
|
|
|
|
cons_show("You have no contacts.");
|
|
|
|
} else {
|
|
|
|
cons_show("All contacts:");
|
|
|
|
cons_show_contacts(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// available
|
|
|
|
} else if (strcmp("available", presence) == 0) {
|
|
|
|
GSList *filtered = NULL;
|
|
|
|
|
2015-02-10 15:30:50 -05:00
|
|
|
GSList *curr = list;
|
2015-05-04 17:23:59 -04:00
|
|
|
while (curr) {
|
2015-02-10 15:30:50 -05:00
|
|
|
PContact contact = curr->data;
|
2014-07-22 18:27:36 -04:00
|
|
|
if (p_contact_is_available(contact)) {
|
|
|
|
filtered = g_slist_append(filtered, contact);
|
|
|
|
}
|
2015-02-10 15:30:50 -05:00
|
|
|
curr = g_slist_next(curr);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2014-07-22 18:27:36 -04:00
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts in group %s are %s.", group, presence);
|
|
|
|
} else {
|
|
|
|
cons_show("%s (%s):", group, presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts are %s.", presence);
|
|
|
|
} else {
|
|
|
|
cons_show("Contacts (%s):", presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:03:17 -05:00
|
|
|
g_slist_free(filtered);
|
2014-07-22 18:27:36 -04:00
|
|
|
|
|
|
|
// unavailable
|
|
|
|
} else if (strcmp("unavailable", presence) == 0) {
|
|
|
|
GSList *filtered = NULL;
|
|
|
|
|
2015-02-10 15:30:50 -05:00
|
|
|
GSList *curr = list;
|
2015-05-04 17:23:59 -04:00
|
|
|
while (curr) {
|
2015-02-10 15:30:50 -05:00
|
|
|
PContact contact = curr->data;
|
2014-07-22 18:27:36 -04:00
|
|
|
if (!p_contact_is_available(contact)) {
|
|
|
|
filtered = g_slist_append(filtered, contact);
|
|
|
|
}
|
2015-02-10 15:30:50 -05:00
|
|
|
curr = g_slist_next(curr);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2014-07-22 18:27:36 -04:00
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts in group %s are %s.", group, presence);
|
|
|
|
} else {
|
|
|
|
cons_show("%s (%s):", group, presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts are %s.", presence);
|
|
|
|
} else {
|
|
|
|
cons_show("Contacts (%s):", presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:03:17 -05:00
|
|
|
g_slist_free(filtered);
|
2014-07-22 18:27:36 -04:00
|
|
|
|
|
|
|
// online, available resources
|
|
|
|
} else if (strcmp("online", presence) == 0) {
|
|
|
|
GSList *filtered = NULL;
|
|
|
|
|
2015-02-10 15:30:50 -05:00
|
|
|
GSList *curr = list;
|
2015-05-04 17:23:59 -04:00
|
|
|
while (curr) {
|
2015-02-10 15:30:50 -05:00
|
|
|
PContact contact = curr->data;
|
2014-07-22 18:27:36 -04:00
|
|
|
if (p_contact_has_available_resource(contact)) {
|
|
|
|
filtered = g_slist_append(filtered, contact);
|
|
|
|
}
|
2015-02-10 15:30:50 -05:00
|
|
|
curr = g_slist_next(curr);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2014-07-22 18:27:36 -04:00
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts in group %s are %s.", group, presence);
|
|
|
|
} else {
|
|
|
|
cons_show("%s (%s):", group, presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts are %s.", presence);
|
|
|
|
} else {
|
|
|
|
cons_show("Contacts (%s):", presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:03:17 -05:00
|
|
|
g_slist_free(filtered);
|
2014-07-22 18:27:36 -04:00
|
|
|
|
|
|
|
// offline, no available resources
|
|
|
|
} else if (strcmp("offline", presence) == 0) {
|
|
|
|
GSList *filtered = NULL;
|
|
|
|
|
2015-02-10 15:30:50 -05:00
|
|
|
GSList *curr = list;
|
2015-05-04 17:23:59 -04:00
|
|
|
while (curr) {
|
2015-02-10 15:30:50 -05:00
|
|
|
PContact contact = curr->data;
|
2014-07-22 18:27:36 -04:00
|
|
|
if (!p_contact_has_available_resource(contact)) {
|
|
|
|
filtered = g_slist_append(filtered, contact);
|
|
|
|
}
|
2015-02-10 15:30:50 -05:00
|
|
|
curr = g_slist_next(curr);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2014-07-22 18:27:36 -04:00
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts in group %s are %s.", group, presence);
|
|
|
|
} else {
|
|
|
|
cons_show("%s (%s):", group, presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts are %s.", presence);
|
|
|
|
} else {
|
|
|
|
cons_show("Contacts (%s):", presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:03:17 -05:00
|
|
|
g_slist_free(filtered);
|
2014-07-22 18:27:36 -04:00
|
|
|
|
|
|
|
// show specific status
|
|
|
|
} else {
|
|
|
|
GSList *filtered = NULL;
|
|
|
|
|
2015-02-10 15:30:50 -05:00
|
|
|
GSList *curr = list;
|
2015-05-04 17:23:59 -04:00
|
|
|
while (curr) {
|
2015-02-10 15:30:50 -05:00
|
|
|
PContact contact = curr->data;
|
2014-07-22 18:27:36 -04:00
|
|
|
if (strcmp(p_contact_presence(contact), presence) == 0) {
|
|
|
|
filtered = g_slist_append(filtered, contact);
|
|
|
|
}
|
2015-02-10 15:30:50 -05:00
|
|
|
curr = g_slist_next(curr);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (group) {
|
2014-07-22 18:27:36 -04:00
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts in group %s are %s.", group, presence);
|
|
|
|
} else {
|
|
|
|
cons_show("%s (%s):", group, presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (filtered == NULL) {
|
|
|
|
cons_show("No contacts are %s.", presence);
|
|
|
|
} else {
|
|
|
|
cons_show("Contacts (%s):", presence);
|
|
|
|
cons_show_contacts(filtered);
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:03:17 -05:00
|
|
|
g_slist_free(filtered);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
2014-11-23 19:32:30 -05:00
|
|
|
|
|
|
|
g_slist_free(list);
|
2014-07-22 18:27:36 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_who(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
2015-06-16 19:15:28 -04:00
|
|
|
} else if (window->type == WIN_MUC) {
|
2015-07-25 21:28:45 -04:00
|
|
|
_who_room(window, command, args);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-07-25 21:28:45 -04:00
|
|
|
_who_roster(window, command, args);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CONSOLE && window->type != WIN_MUC) {
|
2015-11-02 16:24:12 -05:00
|
|
|
status_bar_new(1);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_msg(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *usr = args[0];
|
|
|
|
char *msg = args[1];
|
|
|
|
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-21 16:57:39 -04:00
|
|
|
// send private message when in MUC room
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type == WIN_MUC) {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2015-03-15 19:31:39 -04:00
|
|
|
if (muc_roster_contains_nick(mucwin->roomjid, usr)) {
|
|
|
|
GString *full_jid = g_string_new(mucwin->roomjid);
|
|
|
|
g_string_append(full_jid, "/");
|
|
|
|
g_string_append(full_jid, usr);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-05-03 20:31:27 -04:00
|
|
|
ProfPrivateWin *privwin = wins_get_private(full_jid->str);
|
|
|
|
if (!privwin) {
|
2015-11-05 18:28:21 -05:00
|
|
|
privwin = (ProfPrivateWin*)wins_new_private(full_jid->str);
|
2015-05-03 20:31:27 -04:00
|
|
|
}
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win((ProfWin*)privwin);
|
2015-05-03 20:31:27 -04:00
|
|
|
|
2015-04-21 16:57:39 -04:00
|
|
|
if (msg) {
|
2015-05-03 20:31:27 -04:00
|
|
|
cl_ev_send_priv_msg(privwin, msg);
|
2015-03-15 19:18:50 -04:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-03-15 19:31:39 -04:00
|
|
|
g_string_free(full_jid, TRUE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ui_current_print_line("No such participant \"%s\" in room.", usr);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2014-12-21 19:01:43 -05:00
|
|
|
|
2015-03-15 19:31:39 -04:00
|
|
|
return TRUE;
|
2014-04-22 18:53:15 -04:00
|
|
|
|
2015-04-21 16:57:39 -04:00
|
|
|
// send chat message
|
2015-03-15 19:31:39 -04:00
|
|
|
} else {
|
|
|
|
char *barejid = roster_barejid_from_name(usr);
|
|
|
|
if (barejid == NULL) {
|
|
|
|
barejid = usr;
|
|
|
|
}
|
2014-12-26 19:52:34 -05:00
|
|
|
|
2015-04-29 17:59:44 -04:00
|
|
|
ProfChatWin *chatwin = wins_get_chat(barejid);
|
|
|
|
if (!chatwin) {
|
2015-10-27 19:15:28 -04:00
|
|
|
chatwin = chatwin_new(barejid);
|
2015-04-29 17:59:44 -04:00
|
|
|
}
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win((ProfWin*)chatwin);
|
2015-04-29 17:59:44 -04:00
|
|
|
|
2015-03-16 17:59:11 -04:00
|
|
|
if (msg) {
|
2015-04-29 17:59:44 -04:00
|
|
|
cl_ev_send_msg(chatwin, msg);
|
2015-03-16 17:59:11 -04:00
|
|
|
} else {
|
2014-02-22 20:17:03 -05:00
|
|
|
#ifdef HAVE_LIBOTR
|
2015-03-15 19:31:39 -04:00
|
|
|
if (otr_is_secure(barejid)) {
|
2015-10-27 17:23:56 -04:00
|
|
|
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
|
2015-03-15 19:18:50 -04:00
|
|
|
}
|
2015-03-15 19:31:39 -04:00
|
|
|
#endif
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2015-04-29 17:59:44 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_group(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// list all groups
|
|
|
|
if (args[0] == NULL) {
|
|
|
|
GSList *groups = roster_get_groups();
|
|
|
|
GSList *curr = groups;
|
2015-05-04 17:23:59 -04:00
|
|
|
if (curr) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Groups:");
|
2015-05-04 17:23:59 -04:00
|
|
|
while (curr) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show(" %s", curr->data);
|
|
|
|
curr = g_slist_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free_full(groups, g_free);
|
|
|
|
} else {
|
|
|
|
cons_show("No groups.");
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// show contacts in group
|
|
|
|
if (strcmp(args[0], "show") == 0) {
|
|
|
|
char *group = args[1];
|
|
|
|
if (group == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:25:35 -05:00
|
|
|
GSList *list = roster_get_group(group, ROSTER_ORD_NAME, TRUE);
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show_roster_group(group, list);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add contact to group
|
|
|
|
if (strcmp(args[0], "add") == 0) {
|
|
|
|
char *group = args[1];
|
|
|
|
char *contact = args[2];
|
|
|
|
|
|
|
|
if ((group == NULL) || (contact == NULL)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *barejid = roster_barejid_from_name(contact);
|
|
|
|
if (barejid == NULL) {
|
|
|
|
barejid = contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
PContact pcontact = roster_get_contact(barejid);
|
|
|
|
if (pcontact == NULL) {
|
|
|
|
cons_show("Contact not found in roster: %s", barejid);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-01-05 18:24:48 -05:00
|
|
|
if (p_contact_in_group(pcontact, group)) {
|
|
|
|
const char *display_name = p_contact_name_or_jid(pcontact);
|
|
|
|
ui_contact_already_in_group(display_name, group);
|
|
|
|
} else {
|
|
|
|
roster_send_add_to_group(group, pcontact);
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove contact from group
|
|
|
|
if (strcmp(args[0], "remove") == 0) {
|
|
|
|
char *group = args[1];
|
|
|
|
char *contact = args[2];
|
|
|
|
|
|
|
|
if ((group == NULL) || (contact == NULL)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *barejid = roster_barejid_from_name(contact);
|
|
|
|
if (barejid == NULL) {
|
|
|
|
barejid = contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
PContact pcontact = roster_get_contact(barejid);
|
|
|
|
if (pcontact == NULL) {
|
|
|
|
cons_show("Contact not found in roster: %s", barejid);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-01-05 18:24:48 -05:00
|
|
|
if (!p_contact_in_group(pcontact, group)) {
|
|
|
|
const char *display_name = p_contact_name_or_jid(pcontact);
|
|
|
|
ui_contact_not_in_group(display_name, group);
|
|
|
|
} else {
|
|
|
|
roster_send_remove_from_group(group, pcontact);
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_roster(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
// show roster
|
|
|
|
if (args[0] == NULL) {
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-11-17 20:03:35 -05:00
|
|
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show_roster(list);
|
2014-11-23 19:54:51 -05:00
|
|
|
g_slist_free(list);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
|
2014-11-23 19:54:51 -05:00
|
|
|
// show roster, only online contacts
|
|
|
|
} else if(g_strcmp0(args[0], "online") == 0){
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-23 19:54:51 -05:00
|
|
|
GSList *list = roster_get_contacts_online();
|
2014-11-23 02:34:09 -05:00
|
|
|
cons_show_roster(list);
|
2014-11-23 19:54:51 -05:00
|
|
|
g_slist_free(list);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
|
2014-11-15 18:47:27 -05:00
|
|
|
// set roster size
|
|
|
|
} else if (g_strcmp0(args[0], "size") == 0) {
|
|
|
|
if (!args[1]) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-15 18:47:27 -05:00
|
|
|
return TRUE;
|
2015-03-15 21:03:20 -04:00
|
|
|
}
|
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
2014-11-15 18:47:27 -05:00
|
|
|
prefs_set_roster_size(intval);
|
|
|
|
cons_show("Roster screen size set to: %d%%", intval);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED && prefs_get_boolean(PREF_ROSTER)) {
|
2014-11-15 18:47:27 -05:00
|
|
|
wins_resize_all();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-03-15 21:03:20 -04:00
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
2014-11-15 18:47:27 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-11-19 18:21:51 -05:00
|
|
|
// set header character
|
|
|
|
} else if (g_strcmp0(args[0], "char") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "header") == 0) {
|
|
|
|
if (!args[2]) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else if (g_strcmp0(args[2], "none") == 0) {
|
|
|
|
prefs_clear_roster_header_char();
|
|
|
|
cons_show("Roster header char removed.");
|
|
|
|
rosterwin_roster();
|
|
|
|
} else {
|
|
|
|
prefs_set_roster_header_char(args[2][0]);
|
|
|
|
cons_show("Roster header char set to %c.", args[2][0]);
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2015-11-19 19:06:46 -05:00
|
|
|
} else if (g_strcmp0(args[1], "contact") == 0) {
|
|
|
|
if (!args[2]) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else if (g_strcmp0(args[2], "none") == 0) {
|
|
|
|
prefs_clear_roster_contact_char();
|
|
|
|
cons_show("Roster contact char removed.");
|
|
|
|
rosterwin_roster();
|
|
|
|
} else {
|
|
|
|
prefs_set_roster_contact_char(args[2][0]);
|
|
|
|
cons_show("Roster contact char set to %c.", args[2][0]);
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2015-11-19 18:21:51 -05:00
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
2014-11-10 18:23:02 -05:00
|
|
|
// show/hide roster
|
|
|
|
} else if (g_strcmp0(args[0], "show") == 0) {
|
2014-11-10 18:51:13 -05:00
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("Roster enabled.");
|
|
|
|
prefs_set_boolean(PREF_ROSTER, TRUE);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
ui_show_roster();
|
|
|
|
}
|
2014-11-10 18:51:13 -05:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "offline") == 0) {
|
|
|
|
cons_show("Roster offline enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_OFFLINE, TRUE);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2014-11-10 18:51:13 -05:00
|
|
|
return TRUE;
|
2014-11-10 19:00:10 -05:00
|
|
|
} else if (g_strcmp0(args[1], "resource") == 0) {
|
|
|
|
cons_show("Roster resource enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_RESOURCE, TRUE);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2014-11-10 19:00:10 -05:00
|
|
|
return TRUE;
|
2015-11-15 16:33:48 -05:00
|
|
|
} else if (g_strcmp0(args[1], "presence") == 0) {
|
|
|
|
cons_show("Roster presence enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_PRESENCE, TRUE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "status") == 0) {
|
|
|
|
cons_show("Roster status enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_STATUS, TRUE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-07-08 07:11:56 -04:00
|
|
|
} else if (g_strcmp0(args[1], "empty") == 0) {
|
|
|
|
cons_show("Roster empty enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_EMPTY, TRUE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-11-17 21:02:49 -05:00
|
|
|
} else if (g_strcmp0(args[1], "count") == 0) {
|
|
|
|
cons_show("Roster count enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_COUNT, TRUE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-11-17 21:14:11 -05:00
|
|
|
} else if (g_strcmp0(args[1], "priority") == 0) {
|
|
|
|
cons_show("Roster priority enabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_PRIORITY, TRUE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2014-11-10 18:51:13 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-10 18:51:13 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-11-10 18:23:02 -05:00
|
|
|
} else if (g_strcmp0(args[0], "hide") == 0) {
|
2014-11-10 18:51:13 -05:00
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("Roster disabled.");
|
|
|
|
prefs_set_boolean(PREF_ROSTER, FALSE);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
ui_hide_roster();
|
|
|
|
}
|
2014-11-10 18:51:13 -05:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "offline") == 0) {
|
|
|
|
cons_show("Roster offline disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_OFFLINE, FALSE);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2014-11-10 18:51:13 -05:00
|
|
|
return TRUE;
|
2014-11-10 19:00:10 -05:00
|
|
|
} else if (g_strcmp0(args[1], "resource") == 0) {
|
|
|
|
cons_show("Roster resource disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_RESOURCE, FALSE);
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2014-11-10 19:00:10 -05:00
|
|
|
return TRUE;
|
2015-11-15 16:33:48 -05:00
|
|
|
} else if (g_strcmp0(args[1], "presence") == 0) {
|
|
|
|
cons_show("Roster presence disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_PRESENCE, FALSE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "status") == 0) {
|
|
|
|
cons_show("Roster status disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_STATUS, FALSE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-07-08 07:11:56 -04:00
|
|
|
} else if (g_strcmp0(args[1], "empty") == 0) {
|
|
|
|
cons_show("Roster empty disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_EMPTY, FALSE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-11-17 21:02:49 -05:00
|
|
|
} else if (g_strcmp0(args[1], "count") == 0) {
|
|
|
|
cons_show("Roster count disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_COUNT, FALSE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2015-11-17 21:14:11 -05:00
|
|
|
} else if (g_strcmp0(args[1], "priority") == 0) {
|
|
|
|
cons_show("Roster priority disabled");
|
|
|
|
prefs_set_boolean(PREF_ROSTER_PRIORITY, FALSE);
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
2014-11-10 18:51:13 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-10 18:51:13 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-11-10 19:30:29 -05:00
|
|
|
// roster grouping
|
|
|
|
} else if (g_strcmp0(args[0], "by") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "group") == 0) {
|
|
|
|
cons_show("Grouping roster by roster group");
|
|
|
|
prefs_set_string(PREF_ROSTER_BY, "group");
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2014-11-10 19:30:29 -05:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "presence") == 0) {
|
|
|
|
cons_show("Grouping roster by presence");
|
|
|
|
prefs_set_string(PREF_ROSTER_BY, "presence");
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
2014-11-10 19:30:29 -05:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "none") == 0) {
|
|
|
|
cons_show("Roster grouping disabled");
|
|
|
|
prefs_set_string(PREF_ROSTER_BY, "none");
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
2015-11-17 18:37:33 -05:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
// roster item order
|
|
|
|
} else if (g_strcmp0(args[0], "order") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "name") == 0) {
|
|
|
|
cons_show("Ordering roster by name");
|
|
|
|
prefs_set_string(PREF_ROSTER_ORDER, "name");
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "presence") == 0) {
|
|
|
|
cons_show("Ordering roster by presence");
|
|
|
|
prefs_set_string(PREF_ROSTER_ORDER, "presence");
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
rosterwin_roster();
|
2015-06-13 18:59:33 -04:00
|
|
|
}
|
2014-11-10 19:30:29 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-10 19:30:29 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
// add contact
|
2014-03-16 13:53:41 -04:00
|
|
|
} else if (strcmp(args[0], "add") == 0) {
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-16 13:53:41 -04:00
|
|
|
char *jid = args[1];
|
|
|
|
if (jid == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-03-16 13:53:41 -04:00
|
|
|
} else {
|
|
|
|
char *name = args[2];
|
|
|
|
roster_send_add_new(jid, name);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// remove contact
|
2014-03-16 13:53:41 -04:00
|
|
|
} else if (strcmp(args[0], "remove") == 0) {
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-16 13:53:41 -04:00
|
|
|
char *jid = args[1];
|
|
|
|
if (jid == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-03-16 13:53:41 -04:00
|
|
|
} else {
|
|
|
|
roster_send_remove(jid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
2015-07-08 15:51:39 -04:00
|
|
|
} else if (strcmp(args[0], "remove_all") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "contacts") != 0) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-07-08 15:51:39 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-06-19 19:38:28 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-11-17 20:03:35 -05:00
|
|
|
GSList *all = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
2015-06-19 19:38:28 -04:00
|
|
|
GSList *curr = all;
|
|
|
|
while (curr) {
|
|
|
|
PContact contact = curr->data;
|
|
|
|
roster_send_remove(p_contact_barejid(contact));
|
|
|
|
curr = g_slist_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(all);
|
|
|
|
return TRUE;
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
// change nickname
|
2014-03-16 13:53:41 -04:00
|
|
|
} else if (strcmp(args[0], "nick") == 0) {
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-16 13:53:41 -04:00
|
|
|
char *jid = args[1];
|
|
|
|
if (jid == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *name = args[2];
|
2014-03-16 13:53:41 -04:00
|
|
|
if (name == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-03-16 13:53:41 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
// contact does not exist
|
|
|
|
PContact contact = roster_get_contact(jid);
|
|
|
|
if (contact == NULL) {
|
|
|
|
cons_show("Contact not found in roster: %s", jid);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-01-05 17:55:04 -05:00
|
|
|
const char *barejid = p_contact_barejid(contact);
|
|
|
|
roster_change_name(contact, name);
|
|
|
|
GSList *groups = p_contact_groups(contact);
|
|
|
|
roster_send_name_change(barejid, name, groups);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2014-03-16 13:53:41 -04:00
|
|
|
cons_show("Nickname for %s set to: %s.", jid, name);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// remove nickname
|
|
|
|
} else if (strcmp(args[0], "clearnick") == 0) {
|
2015-06-13 18:59:33 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-16 13:53:41 -04:00
|
|
|
char *jid = args[1];
|
|
|
|
if (jid == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-03-16 13:53:41 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// contact does not exist
|
|
|
|
PContact contact = roster_get_contact(jid);
|
|
|
|
if (contact == NULL) {
|
|
|
|
cons_show("Contact not found in roster: %s", jid);
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
2014-03-16 13:53:41 -04:00
|
|
|
const char *barejid = p_contact_barejid(contact);
|
|
|
|
roster_change_name(contact, NULL);
|
|
|
|
GSList *groups = p_contact_groups(contact);
|
|
|
|
roster_send_name_change(barejid, NULL, groups);
|
|
|
|
|
|
|
|
cons_show("Nickname for %s removed.", jid);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 15:50:21 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_resource(ProfWin *window, const char *const command, gchar **args)
|
2014-12-02 15:50:21 -05:00
|
|
|
{
|
2015-01-10 14:10:10 -05:00
|
|
|
char *cmd = args[0];
|
|
|
|
char *setting = NULL;
|
|
|
|
if (g_strcmp0(cmd, "message") == 0) {
|
|
|
|
setting = args[1];
|
|
|
|
if (!setting) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-01-10 14:10:10 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(setting, command, "Message resource", PREF_RESOURCE_MESSAGE);
|
2015-01-10 14:10:10 -05:00
|
|
|
}
|
|
|
|
} else if (g_strcmp0(cmd, "title") == 0) {
|
|
|
|
setting = args[1];
|
|
|
|
if (!setting) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-01-10 14:10:10 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(setting, command, "Title resource", PREF_RESOURCE_TITLE);
|
2015-01-10 14:10:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2015-01-10 14:10:10 -05:00
|
|
|
cons_show("Resource can only be changed in chat windows.");
|
2014-12-02 15:50:21 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-06-16 19:15:28 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
2014-12-15 20:39:47 -05:00
|
|
|
|
2014-12-02 15:50:21 -05:00
|
|
|
if (g_strcmp0(cmd, "set") == 0) {
|
|
|
|
char *resource = args[1];
|
|
|
|
if (!resource) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-12-02 15:50:21 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-03 18:36:39 -05:00
|
|
|
#ifdef HAVE_LIBOTR
|
2014-12-18 18:57:19 -05:00
|
|
|
if (otr_is_secure(chatwin->barejid)) {
|
2014-12-03 18:36:39 -05:00
|
|
|
cons_show("Cannot choose resource during an OTR session.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-18 18:57:19 -05:00
|
|
|
PContact contact = roster_get_contact(chatwin->barejid);
|
2014-12-02 15:50:21 -05:00
|
|
|
if (!contact) {
|
|
|
|
cons_show("Cannot choose resource for contact not in roster.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_contact_get_resource(contact, resource)) {
|
|
|
|
cons_show("No such resource %s.", resource);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-01-10 13:17:10 -05:00
|
|
|
chatwin->resource_override = strdup(resource);
|
2015-01-11 18:04:22 -05:00
|
|
|
chat_state_free(chatwin->state);
|
|
|
|
chatwin->state = chat_state_new();
|
2015-01-10 16:07:40 -05:00
|
|
|
chat_session_resource_override(chatwin->barejid, resource);
|
2014-12-02 15:50:21 -05:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} else if (g_strcmp0(cmd, "off") == 0) {
|
2015-01-10 13:17:10 -05:00
|
|
|
FREE_SET_NULL(chatwin->resource_override);
|
2015-01-11 18:04:22 -05:00
|
|
|
chat_state_free(chatwin->state);
|
|
|
|
chatwin->state = chat_state_new();
|
2015-01-10 16:07:40 -05:00
|
|
|
chat_session_remove(chatwin->barejid);
|
2014-12-02 15:50:21 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-12-02 15:50:21 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_status(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *usr = args[0];
|
|
|
|
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
switch (window->type)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
case WIN_MUC:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (usr) {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-12-19 19:52:35 -05:00
|
|
|
Occupant *occupant = muc_roster_item(mucwin->roomjid, usr);
|
2014-12-18 18:57:19 -05:00
|
|
|
if (occupant) {
|
2014-12-21 14:40:15 -05:00
|
|
|
win_show_occupant(window, occupant);
|
2014-12-18 18:57:19 -05:00
|
|
|
} else {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_vprint(window, '-', 0, NULL, 0, 0, "", "No such participant \"%s\" in room.", usr);
|
2014-12-18 18:57:19 -05:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("You must specify a nickname.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_CHAT:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (usr) {
|
2013-12-15 11:10:32 -05:00
|
|
|
ui_current_print_line("No parameter required when in chat.");
|
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
PContact pcontact = roster_get_contact(chatwin->barejid);
|
2015-05-04 17:23:59 -04:00
|
|
|
if (pcontact) {
|
2014-12-21 14:40:15 -05:00
|
|
|
win_show_contact(window, pcontact);
|
2014-12-18 18:57:19 -05:00
|
|
|
} else {
|
2015-07-29 18:48:28 -04:00
|
|
|
win_println(window, 0, "Error getting contact info.");
|
2014-12-18 18:57:19 -05:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_PRIVATE:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (usr) {
|
2013-12-15 11:10:32 -05:00
|
|
|
ui_current_print_line("No parameter required when in chat.");
|
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
|
|
|
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
Jid *jid = jid_create(privatewin->fulljid);
|
|
|
|
Occupant *occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
|
|
|
if (occupant) {
|
2014-12-21 14:40:15 -05:00
|
|
|
win_show_occupant(window, occupant);
|
2014-12-18 18:57:19 -05:00
|
|
|
} else {
|
2015-07-29 18:48:28 -04:00
|
|
|
win_println(window, 0, "Error getting contact info.");
|
2014-12-18 18:57:19 -05:00
|
|
|
}
|
|
|
|
jid_destroy(jid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_CONSOLE:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (usr) {
|
2014-04-25 19:36:36 -04:00
|
|
|
char *usr_jid = roster_barejid_from_name(usr);
|
2013-12-15 11:10:32 -05:00
|
|
|
if (usr_jid == NULL) {
|
|
|
|
usr_jid = usr;
|
|
|
|
}
|
|
|
|
cons_show_status(usr_jid);
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_info(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *usr = args[0];
|
|
|
|
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
switch (window->type)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
case WIN_MUC:
|
2014-09-29 19:16:01 -04:00
|
|
|
if (usr) {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
Occupant *occupant = muc_roster_item(mucwin->roomjid, usr);
|
2014-09-29 19:16:01 -04:00
|
|
|
if (occupant) {
|
2015-06-16 19:15:28 -04:00
|
|
|
win_show_occupant_info(window, mucwin->roomjid, occupant);
|
2014-09-29 19:16:01 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("No such occupant \"%s\" in room.", usr);
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2015-03-28 20:55:33 -04:00
|
|
|
iq_room_info_request(mucwin->roomjid, TRUE);
|
2015-11-01 16:54:31 -05:00
|
|
|
mucwin_info(mucwin);
|
2014-10-11 18:37:04 -04:00
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_CHAT:
|
2014-09-29 19:16:01 -04:00
|
|
|
if (usr) {
|
2014-06-03 16:35:27 -04:00
|
|
|
ui_current_print_line("No parameter required when in chat.");
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
PContact pcontact = roster_get_contact(chatwin->barejid);
|
2015-05-04 17:23:59 -04:00
|
|
|
if (pcontact) {
|
2014-12-21 14:40:15 -05:00
|
|
|
win_show_info(window, pcontact);
|
2014-12-18 18:57:19 -05:00
|
|
|
} else {
|
2015-07-29 18:48:28 -04:00
|
|
|
win_println(window, 0, "Error getting contact info.");
|
2014-12-18 18:57:19 -05:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_PRIVATE:
|
2014-09-29 19:16:01 -04:00
|
|
|
if (usr) {
|
2013-12-15 11:10:32 -05:00
|
|
|
ui_current_print_line("No parameter required when in chat.");
|
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
|
|
|
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
Jid *jid = jid_create(privatewin->fulljid);
|
|
|
|
Occupant *occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
|
|
|
if (occupant) {
|
2014-12-21 14:40:15 -05:00
|
|
|
win_show_occupant_info(window, jid->barejid, occupant);
|
2014-12-18 18:57:19 -05:00
|
|
|
} else {
|
2015-07-29 18:48:28 -04:00
|
|
|
win_println(window, 0, "Error getting contact info.");
|
2014-12-18 18:57:19 -05:00
|
|
|
}
|
|
|
|
jid_destroy(jid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_CONSOLE:
|
2014-09-29 19:16:01 -04:00
|
|
|
if (usr) {
|
2014-04-25 19:36:36 -04:00
|
|
|
char *usr_jid = roster_barejid_from_name(usr);
|
2013-12-15 11:10:32 -05:00
|
|
|
if (usr_jid == NULL) {
|
|
|
|
usr_jid = usr;
|
|
|
|
}
|
2015-10-09 04:34:58 -04:00
|
|
|
PContact pcontact = roster_get_contact(usr_jid);
|
2015-05-04 17:23:59 -04:00
|
|
|
if (pcontact) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show_info(pcontact);
|
|
|
|
} else {
|
|
|
|
cons_show("No such contact \"%s\" in roster.", usr);
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_caps(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
2014-09-29 19:16:01 -04:00
|
|
|
Occupant *occupant = NULL;
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
switch (window->type)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
case WIN_MUC:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0]) {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
occupant = muc_roster_item(mucwin->roomjid, args[0]);
|
2014-09-29 19:16:01 -04:00
|
|
|
if (occupant) {
|
2014-12-18 18:57:19 -05:00
|
|
|
Jid *jidp = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
|
2014-09-29 19:16:01 -04:00
|
|
|
cons_show_caps(jidp->fulljid, occupant->presence);
|
2014-09-21 18:05:27 -04:00
|
|
|
jid_destroy(jidp);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("No such participant \"%s\" in room.", args[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_show("No nickname supplied to /caps in chat room.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_CHAT:
|
|
|
|
case WIN_CONSOLE:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0]) {
|
2013-12-15 11:10:32 -05:00
|
|
|
Jid *jid = jid_create(args[0]);
|
|
|
|
|
|
|
|
if (jid->fulljid == NULL) {
|
|
|
|
cons_show("You must provide a full jid to the /caps command.");
|
|
|
|
} else {
|
2015-10-09 04:34:58 -04:00
|
|
|
PContact pcontact = roster_get_contact(jid->barejid);
|
2013-12-15 11:10:32 -05:00
|
|
|
if (pcontact == NULL) {
|
|
|
|
cons_show("Contact not found in roster: %s", jid->barejid);
|
|
|
|
} else {
|
|
|
|
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
|
|
|
|
if (resource == NULL) {
|
|
|
|
cons_show("Could not find resource %s, for contact %s", jid->barejid, jid->resourcepart);
|
|
|
|
} else {
|
2014-09-29 19:16:01 -04:00
|
|
|
cons_show_caps(jid->fulljid, resource->presence);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-20 21:21:52 -04:00
|
|
|
jid_destroy(jid);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("You must provide a jid to the /caps command.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_PRIVATE:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0]) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("No parameter needed to /caps when in private chat.");
|
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
|
|
|
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
Jid *jid = jid_create(privatewin->fulljid);
|
2013-12-15 11:10:32 -05:00
|
|
|
if (jid) {
|
2014-09-29 19:16:01 -04:00
|
|
|
occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
|
|
|
cons_show_caps(jid->resourcepart, occupant->presence);
|
2013-12-15 11:10:32 -05:00
|
|
|
jid_destroy(jid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_software(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
switch (window->type)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
case WIN_MUC:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0]) {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2015-10-09 04:34:58 -04:00
|
|
|
Occupant *occupant = muc_roster_item(mucwin->roomjid, args[0]);
|
2014-09-29 19:16:01 -04:00
|
|
|
if (occupant) {
|
2014-12-18 18:57:19 -05:00
|
|
|
Jid *jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
|
2013-12-15 11:10:32 -05:00
|
|
|
iq_send_software_version(jid->fulljid);
|
|
|
|
jid_destroy(jid);
|
|
|
|
} else {
|
|
|
|
cons_show("No such participant \"%s\" in room.", args[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_show("No nickname supplied to /software in chat room.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_CHAT:
|
2015-08-05 20:56:52 -04:00
|
|
|
if (args[0]) {
|
|
|
|
cons_show("No parameter needed to /software when in chat.");
|
|
|
|
} else {
|
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
|
|
|
|
|
|
char *resource = NULL;
|
|
|
|
ChatSession *session = chat_session_get(chatwin->barejid);
|
|
|
|
if (chatwin->resource_override) {
|
|
|
|
resource = chatwin->resource_override;
|
|
|
|
} else if (session && session->resource) {
|
|
|
|
resource = session->resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource) {
|
|
|
|
GString *fulljid = g_string_new(chatwin->barejid);
|
|
|
|
g_string_append_printf(fulljid, "/%s", resource);
|
|
|
|
iq_send_software_version(fulljid->str);
|
|
|
|
g_string_free(fulljid, TRUE);
|
|
|
|
} else {
|
|
|
|
win_println(window, 0, "Unknown resource for /software command.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-12-15 11:10:32 -05:00
|
|
|
case WIN_CONSOLE:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0]) {
|
2015-07-08 16:05:20 -04:00
|
|
|
Jid *myJid = jid_create(jabber_get_fulljid());
|
2013-12-15 11:10:32 -05:00
|
|
|
Jid *jid = jid_create(args[0]);
|
|
|
|
|
|
|
|
if (jid == NULL || jid->fulljid == NULL) {
|
|
|
|
cons_show("You must provide a full jid to the /software command.");
|
2015-07-08 16:05:20 -04:00
|
|
|
} else if (g_strcmp0(jid->barejid, myJid->barejid) == 0) {
|
|
|
|
cons_show("Cannot request software version for yourself.");
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
iq_send_software_version(jid->fulljid);
|
|
|
|
}
|
2015-07-08 16:05:20 -04:00
|
|
|
jid_destroy(myJid);
|
2013-12-15 11:10:32 -05:00
|
|
|
jid_destroy(jid);
|
|
|
|
} else {
|
|
|
|
cons_show("You must provide a jid to the /software command.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIN_PRIVATE:
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[0]) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("No parameter needed to /software when in private chat.");
|
|
|
|
} else {
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
|
|
|
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_send_software_version(privatewin->fulljid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_join(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-07 19:19:21 -05:00
|
|
|
if (args[0] == NULL) {
|
2015-04-11 18:37:52 -04:00
|
|
|
char *account_name = jabber_get_account_name();
|
|
|
|
ProfAccount *account = accounts_get_account(account_name);
|
|
|
|
|
|
|
|
GString *room_str = g_string_new("");
|
2015-10-12 18:37:11 -04:00
|
|
|
char *uuid = jabber_create_uuid();
|
|
|
|
g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service);
|
|
|
|
jabber_free_uuid(uuid);
|
2015-04-11 18:37:52 -04:00
|
|
|
|
|
|
|
presence_join_room(room_str->str, account->muc_nick, NULL);
|
|
|
|
muc_join(room_str->str, account->muc_nick, NULL, FALSE);
|
|
|
|
|
|
|
|
g_string_free(room_str, TRUE);
|
|
|
|
account_free(account);
|
|
|
|
|
2014-03-07 19:19:21 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
Jid *room_arg = jid_create(args[0]);
|
|
|
|
if (room_arg == NULL) {
|
2014-03-07 19:23:52 -05:00
|
|
|
cons_show_error("Specified room has incorrect format.");
|
|
|
|
cons_show("");
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *room = NULL;
|
|
|
|
char *nick = NULL;
|
2014-02-27 00:31:10 -05:00
|
|
|
char *passwd = NULL;
|
2013-12-15 11:10:32 -05:00
|
|
|
GString *room_str = g_string_new("");
|
2014-03-07 19:19:21 -05:00
|
|
|
char *account_name = jabber_get_account_name();
|
|
|
|
ProfAccount *account = accounts_get_account(account_name);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
// full room jid supplied (room@server)
|
2015-05-04 17:23:59 -04:00
|
|
|
if (room_arg->localpart) {
|
2013-12-15 11:10:32 -05:00
|
|
|
room = args[0];
|
|
|
|
|
|
|
|
// server not supplied (room), use account preference
|
|
|
|
} else {
|
|
|
|
g_string_append(room_str, args[0]);
|
|
|
|
g_string_append(room_str, "@");
|
|
|
|
g_string_append(room_str, account->muc_service);
|
|
|
|
room = room_str->str;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:13:42 -05:00
|
|
|
// Additional args supplied
|
2014-04-14 19:13:32 -04:00
|
|
|
gchar *opt_keys[] = { "nick", "password", NULL };
|
2014-04-14 18:36:00 -04:00
|
|
|
gboolean parsed;
|
|
|
|
|
2014-04-14 19:27:55 -04:00
|
|
|
GHashTable *options = parse_options(&args[1], opt_keys, &parsed);
|
2014-04-14 18:36:00 -04:00
|
|
|
if (!parsed) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-14 18:36:00 -04:00
|
|
|
cons_show("");
|
2015-06-24 15:53:04 -04:00
|
|
|
jid_destroy(room_arg);
|
2014-04-14 18:36:00 -04:00
|
|
|
return TRUE;
|
2014-03-05 14:55:02 -05:00
|
|
|
}
|
2014-03-05 12:39:44 -05:00
|
|
|
|
2014-04-14 18:36:00 -04:00
|
|
|
nick = g_hash_table_lookup(options, "nick");
|
|
|
|
passwd = g_hash_table_lookup(options, "password");
|
|
|
|
|
|
|
|
options_destroy(options);
|
|
|
|
|
2014-03-05 14:55:02 -05:00
|
|
|
// In the case that a nick wasn't provided by the optional args...
|
2015-03-28 22:16:41 -04:00
|
|
|
if (!nick) {
|
2013-12-15 11:10:32 -05:00
|
|
|
nick = account->muc_nick;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:16:41 -04:00
|
|
|
// When no password, check for invite with password
|
|
|
|
if (!passwd) {
|
|
|
|
passwd = muc_invite_password(room);
|
|
|
|
}
|
|
|
|
|
2014-09-28 17:09:20 -04:00
|
|
|
if (!muc_active(room)) {
|
2014-03-08 16:10:23 -05:00
|
|
|
presence_join_room(room, nick, passwd);
|
2014-09-28 17:09:20 -04:00
|
|
|
muc_join(room, nick, passwd, FALSE);
|
|
|
|
} else if (muc_roster_complete(room)) {
|
2014-10-17 19:40:44 -04:00
|
|
|
ui_switch_to_room(room);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
jid_destroy(room_arg);
|
|
|
|
g_string_free(room_str, TRUE);
|
2014-01-22 17:22:01 -05:00
|
|
|
account_free(account);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_invite(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *contact = args[0];
|
|
|
|
char *reason = args[1];
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("You must be in a chat room to send an invite.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *usr_jid = roster_barejid_from_name(contact);
|
|
|
|
if (usr_jid == NULL) {
|
|
|
|
usr_jid = contact;
|
|
|
|
}
|
2014-12-18 18:57:19 -05:00
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
message_send_invite(mucwin->roomjid, usr_jid, reason);
|
2015-05-04 17:23:59 -04:00
|
|
|
if (reason) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".",
|
2014-12-18 18:57:19 -05:00
|
|
|
contact, mucwin->roomjid, reason);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("Room invite sent, contact: %s, room: %s.",
|
2014-12-18 18:57:19 -05:00
|
|
|
contact, mucwin->roomjid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_invites(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2014-09-28 17:09:20 -04:00
|
|
|
GSList *invites = muc_invites();
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show_room_invites(invites);
|
|
|
|
g_slist_free_full(invites, g_free);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_decline(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2014-09-28 17:09:20 -04:00
|
|
|
if (!muc_invites_contain(args[0])) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("No such invite exists.");
|
|
|
|
} else {
|
2014-09-28 17:09:20 -04:00
|
|
|
muc_invites_remove(args[0]);
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Declined invite to %s.", args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:27:34 -04:00
|
|
|
gboolean
|
2015-06-16 19:15:28 -04:00
|
|
|
cmd_form_field(ProfWin *window, char *tag, gchar **args)
|
2014-10-18 22:27:34 -04:00
|
|
|
{
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC_CONFIG) {
|
2014-12-09 20:14:11 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
|
2014-12-15 20:39:47 -05:00
|
|
|
DataForm *form = confwin->form;
|
2014-10-18 22:27:34 -04:00
|
|
|
if (form) {
|
|
|
|
if (!form_tag_exists(form, tag)) {
|
|
|
|
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
form_field_type_t field_type = form_get_field_type(form, tag);
|
|
|
|
char *cmd = NULL;
|
|
|
|
char *value = NULL;
|
|
|
|
gboolean valid = FALSE;
|
|
|
|
gboolean added = FALSE;
|
|
|
|
gboolean removed = FALSE;
|
|
|
|
|
|
|
|
switch (field_type) {
|
|
|
|
case FIELD_BOOLEAN:
|
|
|
|
value = args[0];
|
|
|
|
if (g_strcmp0(value, "on") == 0) {
|
|
|
|
form_set_value(form, tag, "1");
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else if (g_strcmp0(value, "off") == 0) {
|
|
|
|
form_set_value(form, tag, "0");
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIELD_TEXT_PRIVATE:
|
|
|
|
case FIELD_TEXT_SINGLE:
|
|
|
|
case FIELD_JID_SINGLE:
|
|
|
|
value = args[0];
|
|
|
|
if (value == NULL) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
form_set_value(form, tag, value);
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIELD_LIST_SINGLE:
|
|
|
|
value = args[0];
|
|
|
|
if ((value == NULL) || !form_field_contains_option(form, tag, value)) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
form_set_value(form, tag, value);
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIELD_TEXT_MULTI:
|
|
|
|
cmd = args[0];
|
|
|
|
if (cmd) {
|
|
|
|
value = args[1];
|
|
|
|
}
|
|
|
|
if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value == NULL) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(cmd, "add") == 0) {
|
|
|
|
form_add_value(form, tag, value);
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "remove") == 0) {
|
|
|
|
if (!g_str_has_prefix(value, "val")) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strlen(value) < 4) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = strtol(&value[3], NULL, 10);
|
|
|
|
if ((index < 1) || (index > form_get_value_count(form, tag))) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
removed = form_remove_text_multi_value(form, tag, index);
|
|
|
|
if (removed) {
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("Could not remove %s from %s", value, tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIELD_LIST_MULTI:
|
|
|
|
cmd = args[0];
|
|
|
|
if (cmd) {
|
|
|
|
value = args[1];
|
|
|
|
}
|
|
|
|
if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value == NULL) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "add") == 0) {
|
|
|
|
valid = form_field_contains_option(form, tag, value);
|
|
|
|
if (valid) {
|
|
|
|
added = form_add_unique_value(form, tag, value);
|
|
|
|
if (added) {
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("Value %s already selected for %s", value, tag);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "remove") == 0) {
|
|
|
|
valid = form_field_contains_option(form, tag, value);
|
|
|
|
if (valid == TRUE) {
|
|
|
|
removed = form_remove_value(form, tag, value);
|
|
|
|
if (removed) {
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("Value %s is not currently set for %s", value, tag);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIELD_JID_MULTI:
|
|
|
|
cmd = args[0];
|
|
|
|
if (cmd) {
|
|
|
|
value = args[1];
|
|
|
|
}
|
|
|
|
if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value == NULL) {
|
|
|
|
ui_current_print_line("Invalid command, usage:");
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-10-23 19:21:00 -04:00
|
|
|
ui_current_print_line("");
|
2014-10-18 22:27:34 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "add") == 0) {
|
|
|
|
added = form_add_unique_value(form, tag, value);
|
|
|
|
if (added) {
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("JID %s already exists in %s", value, tag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_strcmp0(args[0], "remove") == 0) {
|
2014-12-09 20:14:11 -05:00
|
|
|
removed = form_remove_value(form, tag, value);
|
2014-10-18 22:27:34 -04:00
|
|
|
if (removed) {
|
|
|
|
ui_current_print_line("Field updated...");
|
2015-11-02 17:19:01 -05:00
|
|
|
mucconfwin_show_form_field(confwin, form, tag);
|
2014-10-18 22:27:34 -04:00
|
|
|
} else {
|
|
|
|
ui_current_print_line("Field %s does not contain %s", tag, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:36:42 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_form(ProfWin *window, const char *const command, gchar **args)
|
2014-09-02 19:36:42 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC_CONFIG) {
|
2014-09-15 16:33:25 -04:00
|
|
|
cons_show("Command '/form' does not apply to this window.");
|
2014-09-03 17:56:33 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-09-02 19:58:20 -04:00
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
if ((g_strcmp0(args[0], "submit") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "cancel") != 0) &&
|
2014-09-15 17:51:53 -04:00
|
|
|
(g_strcmp0(args[0], "show") != 0) &&
|
2014-10-18 22:27:34 -04:00
|
|
|
(g_strcmp0(args[0], "help") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-09-03 17:56:33 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-09-02 19:58:20 -04:00
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
|
|
|
|
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
|
2014-09-10 19:01:44 -04:00
|
|
|
|
2014-09-15 17:51:53 -04:00
|
|
|
if (g_strcmp0(args[0], "show") == 0) {
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_show_form(confwin);
|
2014-09-15 17:51:53 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-16 15:52:38 -04:00
|
|
|
if (g_strcmp0(args[0], "help") == 0) {
|
|
|
|
char *tag = args[1];
|
2015-05-04 17:23:59 -04:00
|
|
|
if (tag) {
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_field_help(confwin, tag);
|
2014-09-16 15:52:38 -04:00
|
|
|
} else {
|
2015-11-02 17:05:17 -05:00
|
|
|
mucconfwin_form_help(confwin);
|
2014-09-16 15:52:38 -04:00
|
|
|
|
|
|
|
const gchar **help_text = NULL;
|
|
|
|
Command *command = g_hash_table_lookup(commands, "/form");
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (command) {
|
2015-07-25 21:05:53 -04:00
|
|
|
help_text = command->help.synopsis;
|
2014-09-16 15:52:38 -04:00
|
|
|
}
|
|
|
|
|
2014-12-21 14:40:15 -05:00
|
|
|
ui_show_lines((ProfWin*) confwin, help_text);
|
2014-09-16 15:52:38 -04:00
|
|
|
}
|
|
|
|
ui_current_print_line("");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
if (g_strcmp0(args[0], "submit") == 0) {
|
2014-12-21 17:01:56 -05:00
|
|
|
iq_submit_room_config(confwin->roomjid, confwin->form);
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
2014-10-31 21:48:36 -04:00
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
if (g_strcmp0(args[0], "cancel") == 0) {
|
2014-12-21 17:01:56 -05:00
|
|
|
iq_room_config_cancel(confwin->roomjid);
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
2014-10-31 21:48:36 -04:00
|
|
|
|
|
|
|
if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
|
2014-12-15 20:39:47 -05:00
|
|
|
if (confwin->form) {
|
|
|
|
cmd_autocomplete_remove_form_fields(confwin->form);
|
2014-10-18 18:56:10 -04:00
|
|
|
}
|
2015-10-13 15:46:59 -04:00
|
|
|
|
|
|
|
int num = wins_get_num(window);
|
|
|
|
|
2015-04-30 17:09:39 -04:00
|
|
|
ProfWin *new_current = (ProfWin*)wins_get_muc(confwin->roomjid);
|
|
|
|
if (!new_current) {
|
|
|
|
new_current = wins_get_console();
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win(new_current);
|
2015-10-13 15:46:59 -04:00
|
|
|
wins_close_by_num(num);
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:35:50 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_kick(ProfWin *window, const char *const command, gchar **args)
|
2014-10-10 08:35:50 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2014-10-10 08:35:50 -04:00
|
|
|
cons_show("Command '/kick' only applies in chat rooms.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-10-10 08:35:50 -04:00
|
|
|
|
|
|
|
char *nick = args[0];
|
|
|
|
if (nick) {
|
2014-12-18 18:57:19 -05:00
|
|
|
if (muc_roster_contains_nick(mucwin->roomjid, nick)) {
|
2014-10-10 08:35:50 -04:00
|
|
|
char *reason = args[1];
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_kick_occupant(mucwin->roomjid, nick, reason);
|
2014-10-10 08:35:50 -04:00
|
|
|
} else {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_vprint((ProfWin*) mucwin, '!', 0, NULL, 0, 0, "", "Occupant does not exist: %s", nick);
|
2014-10-10 08:35:50 -04:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-10 08:35:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-11 17:43:54 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_ban(ProfWin *window, const char *const command, gchar **args)
|
2014-10-11 17:43:54 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2014-10-18 15:35:23 -04:00
|
|
|
cons_show("Command '/ban' only applies in chat rooms.");
|
2014-10-11 17:43:54 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-10-11 17:43:54 -04:00
|
|
|
|
|
|
|
char *jid = args[0];
|
|
|
|
if (jid) {
|
|
|
|
char *reason = args[1];
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_affiliation_set(mucwin->roomjid, jid, "outcast", reason);
|
2014-10-11 17:43:54 -04:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 17:43:54 -04:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-11 18:13:48 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_subject(ProfWin *window, const char *const command, gchar **args)
|
2014-10-11 18:13:48 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2014-10-11 18:13:48 -04:00
|
|
|
cons_show("Command '/room' does not apply to this window.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-10-11 18:13:48 -04:00
|
|
|
|
|
|
|
if (args[0] == NULL) {
|
2014-12-18 18:57:19 -05:00
|
|
|
char *subject = muc_subject(mucwin->roomjid);
|
2014-10-11 18:13:48 -04:00
|
|
|
if (subject) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: ");
|
|
|
|
win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject);
|
2014-10-11 18:13:48 -04:00
|
|
|
} else {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room has no subject");
|
2014-10-11 18:13:48 -04:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "set") == 0) {
|
|
|
|
if (args[1]) {
|
2014-12-18 18:57:19 -05:00
|
|
|
message_send_groupchat_subject(mucwin->roomjid, args[1]);
|
2014-10-11 18:13:48 -04:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-10-29 16:55:37 -04:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-29 17:21:41 -04:00
|
|
|
if (g_strcmp0(args[0], "edit") == 0) {
|
|
|
|
if (args[1]) {
|
|
|
|
message_send_groupchat_subject(mucwin->roomjid, args[1]);
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-29 17:02:46 -04:00
|
|
|
if (g_strcmp0(args[0], "prepend") == 0) {
|
|
|
|
if (args[1]) {
|
|
|
|
char *old_subject = muc_subject(mucwin->roomjid);
|
|
|
|
if (old_subject) {
|
|
|
|
GString *new_subject = g_string_new(args[1]);
|
|
|
|
g_string_append(new_subject, old_subject);
|
|
|
|
message_send_groupchat_subject(mucwin->roomjid, new_subject->str);
|
|
|
|
g_string_free(new_subject, TRUE);
|
|
|
|
} else {
|
|
|
|
win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room does not have a subject, use /subject set <subject>");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-29 16:55:37 -04:00
|
|
|
if (g_strcmp0(args[0], "append") == 0) {
|
|
|
|
if (args[1]) {
|
|
|
|
char *old_subject = muc_subject(mucwin->roomjid);
|
|
|
|
if (old_subject) {
|
|
|
|
GString *new_subject = g_string_new(old_subject);
|
|
|
|
g_string_append(new_subject, args[1]);
|
|
|
|
message_send_groupchat_subject(mucwin->roomjid, new_subject->str);
|
|
|
|
g_string_free(new_subject, TRUE);
|
|
|
|
} else {
|
|
|
|
win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room does not have a subject, use /subject set <subject>");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 18:13:48 -04:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "clear") == 0) {
|
2014-12-18 18:57:19 -05:00
|
|
|
message_send_groupchat_subject(mucwin->roomjid, NULL);
|
2014-10-11 18:13:48 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 18:13:48 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_affiliation(ProfWin *window, const char *const command, gchar **args)
|
2014-09-15 16:33:25 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2014-10-11 19:43:58 -04:00
|
|
|
cons_show("Command '/affiliation' does not apply to this window.");
|
2014-09-15 16:33:25 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
char *cmd = args[0];
|
|
|
|
if (cmd == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *affiliation = args[1];
|
2015-05-04 17:23:59 -04:00
|
|
|
if (affiliation &&
|
2014-10-11 20:32:15 -04:00
|
|
|
(g_strcmp0(affiliation, "owner") != 0) &&
|
2014-10-11 19:43:58 -04:00
|
|
|
(g_strcmp0(affiliation, "admin") != 0) &&
|
|
|
|
(g_strcmp0(affiliation, "member") != 0) &&
|
|
|
|
(g_strcmp0(affiliation, "none") != 0) &&
|
|
|
|
(g_strcmp0(affiliation, "outcast") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-09-15 16:33:25 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-09-15 16:33:25 -04:00
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
if (g_strcmp0(cmd, "list") == 0) {
|
2014-10-11 20:32:15 -04:00
|
|
|
if (!affiliation) {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_affiliation_list(mucwin->roomjid, "owner");
|
|
|
|
iq_room_affiliation_list(mucwin->roomjid, "admin");
|
|
|
|
iq_room_affiliation_list(mucwin->roomjid, "member");
|
2014-12-19 19:52:35 -05:00
|
|
|
iq_room_affiliation_list(mucwin->roomjid, "outcast");
|
2014-10-11 20:32:15 -04:00
|
|
|
} else if (g_strcmp0(affiliation, "none") == 0) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print((ProfWin*) mucwin, '!', 0, NULL, 0, 0, "", "Cannot list users with no affiliation.");
|
2014-10-11 19:43:58 -04:00
|
|
|
} else {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_affiliation_list(mucwin->roomjid, affiliation);
|
2014-10-11 19:43:58 -04:00
|
|
|
}
|
|
|
|
return TRUE;
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
if (g_strcmp0(cmd, "set") == 0) {
|
2014-10-11 20:32:15 -04:00
|
|
|
if (!affiliation) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 20:32:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
char *jid = args[2];
|
|
|
|
if (jid == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-04 18:40:36 -04:00
|
|
|
return TRUE;
|
2014-10-11 19:43:58 -04:00
|
|
|
} else {
|
|
|
|
char *reason = args[3];
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_affiliation_set(mucwin->roomjid, jid, affiliation, reason);
|
2014-10-04 18:40:36 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-11 19:43:58 -04:00
|
|
|
}
|
2014-10-04 18:40:36 -04:00
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-04 18:40:36 -04:00
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_role(ProfWin *window, const char *const command, gchar **args)
|
2014-10-11 19:43:58 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
2014-10-04 18:40:36 -04:00
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
2014-10-04 18:40:36 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2014-10-11 19:43:58 -04:00
|
|
|
cons_show("Command '/role' does not apply to this window.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *cmd = args[0];
|
|
|
|
if (cmd == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *role = args[1];
|
2015-05-04 17:23:59 -04:00
|
|
|
if (role &&
|
2014-10-11 20:32:15 -04:00
|
|
|
(g_strcmp0(role, "visitor") != 0) &&
|
2014-10-11 19:43:58 -04:00
|
|
|
(g_strcmp0(role, "participant") != 0) &&
|
|
|
|
(g_strcmp0(role, "moderator") != 0) &&
|
|
|
|
(g_strcmp0(role, "none") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-10-11 19:43:58 -04:00
|
|
|
|
|
|
|
if (g_strcmp0(cmd, "list") == 0) {
|
2014-10-11 20:32:15 -04:00
|
|
|
if (!role) {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_role_list(mucwin->roomjid, "moderator");
|
|
|
|
iq_room_role_list(mucwin->roomjid, "participant");
|
|
|
|
iq_room_role_list(mucwin->roomjid, "visitor");
|
2014-10-11 20:32:15 -04:00
|
|
|
} else if (g_strcmp0(role, "none") == 0) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print((ProfWin*) mucwin, '!', 0, NULL, 0, 0, "", "Cannot list users with no role.");
|
2014-10-11 19:43:58 -04:00
|
|
|
} else {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_role_list(mucwin->roomjid, role);
|
2014-10-06 16:42:09 -04:00
|
|
|
}
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-06 16:42:09 -04:00
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
if (g_strcmp0(cmd, "set") == 0) {
|
2014-10-11 20:32:15 -04:00
|
|
|
if (!role) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 20:32:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
char *nick = args[2];
|
|
|
|
if (nick == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-06 16:42:09 -04:00
|
|
|
return TRUE;
|
2014-10-11 19:43:58 -04:00
|
|
|
} else {
|
|
|
|
char *reason = args[3];
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_room_role_set(mucwin->roomjid, nick, role, reason);
|
2014-10-06 16:42:09 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-11 19:43:58 -04:00
|
|
|
}
|
2014-10-06 16:42:09 -04:00
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_room(ProfWin *window, const char *const command, gchar **args)
|
2014-10-11 19:43:58 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
2014-10-06 16:42:09 -04:00
|
|
|
|
2014-10-11 19:43:58 -04:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
2014-09-30 19:46:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2014-10-11 19:43:58 -04:00
|
|
|
cons_show("Command '/room' does not apply to this window.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((g_strcmp0(args[0], "accept") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "destroy") != 0) &&
|
|
|
|
(g_strcmp0(args[0], "config") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-11 19:43:58 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-12-21 14:40:15 -05:00
|
|
|
int num = wins_get_num(window);
|
2014-10-11 19:43:58 -04:00
|
|
|
|
|
|
|
int ui_index = num;
|
|
|
|
if (ui_index == 10) {
|
|
|
|
ui_index = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
if (g_strcmp0(args[0], "accept") == 0) {
|
2014-12-18 18:57:19 -05:00
|
|
|
gboolean requires_config = muc_requires_config(mucwin->roomjid);
|
2014-09-15 16:33:25 -04:00
|
|
|
if (!requires_config) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Current room does not require configuration.");
|
2014-09-15 16:33:25 -04:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_confirm_instant_room(mucwin->roomjid);
|
|
|
|
muc_set_requires_config(mucwin->roomjid, FALSE);
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room unlocked.");
|
2014-09-15 16:33:25 -04:00
|
|
|
return TRUE;
|
2014-09-10 19:17:42 -04:00
|
|
|
}
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
2014-09-10 19:17:42 -04:00
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
if (g_strcmp0(args[0], "destroy") == 0) {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_destroy_room(mucwin->roomjid);
|
2014-09-15 16:33:25 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-09-10 19:17:42 -04:00
|
|
|
|
2014-09-15 16:33:25 -04:00
|
|
|
if (g_strcmp0(args[0], "config") == 0) {
|
2014-12-21 17:01:56 -05:00
|
|
|
ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid);
|
2014-12-18 18:57:19 -05:00
|
|
|
|
2015-04-30 17:09:39 -04:00
|
|
|
if (confwin) {
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win((ProfWin*)confwin);
|
2014-09-15 16:33:25 -04:00
|
|
|
} else {
|
2014-12-18 18:57:19 -05:00
|
|
|
iq_request_room_config_form(mucwin->roomjid);
|
2014-09-15 16:33:25 -04:00
|
|
|
}
|
2014-09-10 19:17:42 -04:00
|
|
|
return TRUE;
|
2014-09-02 19:58:20 -04:00
|
|
|
}
|
2014-09-03 17:56:33 -04:00
|
|
|
|
2014-09-02 19:36:42 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-09 08:16:36 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_occupants(ProfWin *window, const char *const command, gchar **args)
|
2014-10-09 08:16:36 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-11-15 18:47:27 -05:00
|
|
|
if (g_strcmp0(args[0], "size") == 0) {
|
|
|
|
if (!args[1]) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-11-15 18:47:27 -05:00
|
|
|
return TRUE;
|
2015-03-15 21:03:20 -04:00
|
|
|
} else {
|
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
|
|
|
prefs_set_occupants_size(intval);
|
|
|
|
cons_show("Occupants screen size set to: %d%%", intval);
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-11-15 18:47:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 17:39:57 -04:00
|
|
|
if (g_strcmp0(args[0], "default") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "show") == 0) {
|
2015-04-11 21:14:37 -04:00
|
|
|
if (g_strcmp0(args[2], "jid") == 0) {
|
|
|
|
cons_show("Occupant jids enabled.");
|
|
|
|
prefs_set_boolean(PREF_OCCUPANTS_JID, TRUE);
|
|
|
|
} else {
|
|
|
|
cons_show("Occupant list enabled.");
|
|
|
|
prefs_set_boolean(PREF_OCCUPANTS, TRUE);
|
|
|
|
}
|
2014-10-09 17:39:57 -04:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "hide") == 0) {
|
2015-04-11 21:14:37 -04:00
|
|
|
if (g_strcmp0(args[2], "jid") == 0) {
|
|
|
|
cons_show("Occupant jids disabled.");
|
|
|
|
prefs_set_boolean(PREF_OCCUPANTS_JID, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Occupant list disabled.");
|
|
|
|
prefs_set_boolean(PREF_OCCUPANTS, FALSE);
|
|
|
|
}
|
2014-10-09 17:39:57 -04:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-09 17:39:57 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2015-04-11 21:14:37 -04:00
|
|
|
cons_show("Cannot apply setting when not in chat room.");
|
2014-10-09 08:16:36 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-10-09 08:16:36 -04:00
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "show") == 0) {
|
2015-04-11 21:14:37 -04:00
|
|
|
if (g_strcmp0(args[1], "jid") == 0) {
|
|
|
|
mucwin->showjid = TRUE;
|
2015-11-01 19:57:13 -05:00
|
|
|
mucwin_update_occupants(mucwin);
|
2015-04-11 21:14:37 -04:00
|
|
|
} else {
|
2015-11-01 19:59:27 -05:00
|
|
|
mucwin_show_occupants(mucwin);
|
2015-04-11 21:14:37 -04:00
|
|
|
}
|
2014-10-09 08:16:36 -04:00
|
|
|
} else if (g_strcmp0(args[0], "hide") == 0) {
|
2015-04-11 21:14:37 -04:00
|
|
|
if (g_strcmp0(args[1], "jid") == 0) {
|
|
|
|
mucwin->showjid = FALSE;
|
2015-11-01 19:57:13 -05:00
|
|
|
mucwin_update_occupants(mucwin);
|
2015-04-11 21:14:37 -04:00
|
|
|
} else {
|
2015-11-01 20:01:37 -05:00
|
|
|
mucwin_hide_occupants(mucwin);
|
2015-04-11 21:14:37 -04:00
|
|
|
}
|
2014-10-09 08:16:36 -04:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-10-09 08:16:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_rooms(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0] == NULL) {
|
|
|
|
ProfAccount *account = accounts_get_account(jabber_get_account_name());
|
|
|
|
iq_room_list_request(account->muc_service);
|
2014-10-31 21:48:36 -04:00
|
|
|
account_free(account);
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
iq_room_list_request(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
2014-02-01 11:24:51 -05:00
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
2014-02-01 11:16:56 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-14 14:57:29 -05:00
|
|
|
gchar *cmd = args[0];
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type == WIN_MUC && cmd == NULL) {
|
2014-08-19 17:51:00 -04:00
|
|
|
// default to current nickname, password, and autojoin "on"
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2014-12-18 18:57:19 -05:00
|
|
|
char *nick = muc_nick(mucwin->roomjid);
|
|
|
|
char *password = muc_password(mucwin->roomjid);
|
|
|
|
gboolean added = bookmark_add(mucwin->roomjid, nick, password, "on");
|
2014-12-14 14:57:29 -05:00
|
|
|
if (added) {
|
2014-12-18 18:57:19 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "Bookmark added for %s.", mucwin->roomjid);
|
2014-08-19 17:51:00 -04:00
|
|
|
} else {
|
2014-12-18 18:57:19 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "Bookmark already exists for %s.", mucwin->roomjid);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2014-12-14 14:57:29 -05:00
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2014-08-19 17:51:00 -04:00
|
|
|
} else {
|
|
|
|
if (cmd == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-05-09 19:50:43 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-19 17:51:00 -04:00
|
|
|
if (strcmp(cmd, "list") == 0) {
|
|
|
|
const GList *bookmarks = bookmark_get_list();
|
|
|
|
cons_show_bookmarks(bookmarks);
|
|
|
|
} else {
|
|
|
|
char *jid = args[1];
|
|
|
|
if (jid == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-05-09 19:50:43 -04:00
|
|
|
cons_show("");
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-19 17:51:00 -04:00
|
|
|
if (strcmp(cmd, "remove") == 0) {
|
|
|
|
gboolean removed = bookmark_remove(jid);
|
|
|
|
if (removed) {
|
|
|
|
cons_show("Bookmark removed for %s.", jid);
|
2014-08-17 16:22:12 -04:00
|
|
|
} else {
|
2014-08-19 17:51:00 -04:00
|
|
|
cons_show("No bookmark exists for %s.", jid);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(cmd, "join") == 0) {
|
|
|
|
gboolean joined = bookmark_join(jid);
|
|
|
|
if (!joined) {
|
|
|
|
cons_show("No bookmark exists for %s.", jid);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
|
|
|
|
gboolean parsed;
|
|
|
|
|
|
|
|
GHashTable *options = parse_options(&args[2], opt_keys, &parsed);
|
|
|
|
if (!parsed) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-08-19 17:51:00 -04:00
|
|
|
cons_show("");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *nick = g_hash_table_lookup(options, "nick");
|
|
|
|
char *password = g_hash_table_lookup(options, "password");
|
|
|
|
char *autojoin = g_hash_table_lookup(options, "autojoin");
|
|
|
|
|
2015-05-04 17:23:59 -04:00
|
|
|
if (autojoin) {
|
2014-08-19 17:51:00 -04:00
|
|
|
if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-08-19 17:51:00 -04:00
|
|
|
cons_show("");
|
|
|
|
return TRUE;
|
2014-08-17 16:22:12 -04:00
|
|
|
}
|
2014-02-01 19:00:08 -05:00
|
|
|
}
|
2014-08-19 17:51:00 -04:00
|
|
|
|
|
|
|
if (strcmp(cmd, "add") == 0) {
|
|
|
|
if (strchr(jid, '@')==NULL) {
|
|
|
|
cons_show("Can't add bookmark with JID '%s'; should be '%s@domain.tld'", jid, jid);
|
|
|
|
} else {
|
|
|
|
gboolean added = bookmark_add(jid, nick, password, autojoin);
|
|
|
|
if (added) {
|
|
|
|
cons_show("Bookmark added for %s.", jid);
|
|
|
|
} else {
|
|
|
|
cons_show("Bookmark already exists, use /bookmark update to edit.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (strcmp(cmd, "update") == 0) {
|
|
|
|
gboolean updated = bookmark_update(jid, nick, password, autojoin);
|
|
|
|
if (updated) {
|
|
|
|
cons_show("Bookmark updated.");
|
|
|
|
} else {
|
|
|
|
cons_show("No bookmark exists for %s.", jid);
|
|
|
|
}
|
2014-02-01 19:37:37 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-02-01 19:37:37 -05:00
|
|
|
}
|
2014-05-09 19:50:43 -04:00
|
|
|
|
2014-08-19 17:51:00 -04:00
|
|
|
options_destroy(options);
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_disco(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currenlty connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GString *jid = g_string_new("");
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[1]) {
|
2013-12-15 11:10:32 -05:00
|
|
|
jid = g_string_append(jid, args[1]);
|
|
|
|
} else {
|
|
|
|
Jid *jidp = jid_create(jabber_get_fulljid());
|
|
|
|
jid = g_string_append(jid, jidp->domainpart);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "info") == 0) {
|
|
|
|
iq_disco_info_request(jid->str);
|
|
|
|
} else {
|
|
|
|
iq_disco_items_request(jid->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free(jid, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-28 19:01:38 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_lastactivity(ProfWin *window, const char *const command, gchar **args)
|
2015-09-28 19:01:38 -04:00
|
|
|
{
|
2015-10-15 18:32:47 -04:00
|
|
|
if ((g_strcmp0(args[0], "on") == 0) || (g_strcmp0(args[0], "off") == 0)) {
|
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Last activity", PREF_LASTACTIVITY);
|
|
|
|
}
|
|
|
|
|
2015-09-28 19:01:38 -04:00
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currenlty connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0] == NULL) {
|
|
|
|
Jid *jidp = jid_create(jabber_get_fulljid());
|
|
|
|
GString *jid = g_string_new(jidp->domainpart);
|
|
|
|
|
|
|
|
iq_last_activity_request(jid->str);
|
|
|
|
|
|
|
|
g_string_free(jid, TRUE);
|
|
|
|
jid_destroy(jidp);
|
2015-10-14 17:09:18 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2015-09-28 19:01:38 -04:00
|
|
|
} else {
|
|
|
|
iq_last_activity_request(args[0]);
|
2015-10-14 17:09:18 -04:00
|
|
|
return TRUE;
|
2015-09-28 19:01:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_nick(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("You can only change your nickname in a chat room window.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2013-12-15 11:10:32 -05:00
|
|
|
char *nick = args[0];
|
2014-12-18 18:57:19 -05:00
|
|
|
presence_change_room_nick(mucwin->roomjid, nick);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:56:33 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_alias(ProfWin *window, const char *const command, gchar **args)
|
2014-01-23 14:56:33 -05:00
|
|
|
{
|
2014-01-23 17:29:53 -05:00
|
|
|
char *subcmd = args[0];
|
|
|
|
|
|
|
|
if (strcmp(subcmd, "add") == 0) {
|
|
|
|
char *alias = args[1];
|
|
|
|
if (alias == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-01-23 17:29:53 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2014-11-30 18:34:54 -05:00
|
|
|
char *alias_p = alias;
|
|
|
|
GString *ac_value = g_string_new("");
|
|
|
|
if (alias[0] == '/') {
|
|
|
|
g_string_append(ac_value, alias);
|
|
|
|
alias_p = &alias[1];
|
|
|
|
} else {
|
|
|
|
g_string_append(ac_value, "/");
|
|
|
|
g_string_append(ac_value, alias);
|
|
|
|
}
|
2014-01-24 20:39:12 -05:00
|
|
|
|
2014-01-23 17:29:53 -05:00
|
|
|
char *value = args[2];
|
|
|
|
if (value == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-01-24 20:39:12 -05:00
|
|
|
g_string_free(ac_value, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
} else if (cmd_exists(ac_value->str)) {
|
2014-02-15 16:17:31 -05:00
|
|
|
cons_show("Command or alias '%s' already exists.", ac_value->str);
|
2014-01-24 20:39:12 -05:00
|
|
|
g_string_free(ac_value, TRUE);
|
2014-01-23 17:29:53 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2014-11-30 18:34:54 -05:00
|
|
|
prefs_add_alias(alias_p, value);
|
2014-01-24 20:39:12 -05:00
|
|
|
cmd_autocomplete_add(ac_value->str);
|
2014-11-30 18:34:54 -05:00
|
|
|
cmd_alias_add(alias_p);
|
|
|
|
cons_show("Command alias added %s -> %s", ac_value->str, value);
|
2014-01-24 20:39:12 -05:00
|
|
|
g_string_free(ac_value, TRUE);
|
2014-01-23 17:29:53 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (strcmp(subcmd, "remove") == 0) {
|
|
|
|
char *alias = args[1];
|
|
|
|
if (alias == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-01-23 17:29:53 -05:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2014-11-30 18:34:54 -05:00
|
|
|
if (alias[0] == '/') {
|
|
|
|
alias = &alias[1];
|
|
|
|
}
|
2014-01-23 17:29:53 -05:00
|
|
|
gboolean removed = prefs_remove_alias(alias);
|
|
|
|
if (!removed) {
|
|
|
|
cons_show("No such command alias /%s", alias);
|
|
|
|
} else {
|
2014-01-23 18:53:20 -05:00
|
|
|
GString *ac_value = g_string_new("/");
|
|
|
|
g_string_append(ac_value, alias);
|
|
|
|
cmd_autocomplete_remove(ac_value->str);
|
2014-01-24 20:00:51 -05:00
|
|
|
cmd_alias_remove(alias);
|
2014-01-23 18:53:20 -05:00
|
|
|
g_string_free(ac_value, TRUE);
|
2014-01-23 17:29:53 -05:00
|
|
|
cons_show("Command alias removed -> /%s", alias);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (strcmp(subcmd, "list") == 0) {
|
|
|
|
GList *aliases = prefs_get_aliases();
|
|
|
|
cons_show_aliases(aliases);
|
|
|
|
prefs_free_aliases(aliases);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-01-23 17:29:53 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-01-23 14:56:33 -05:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_tiny(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *url = args[0];
|
2015-03-16 19:03:31 -04:00
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE) {
|
2015-03-16 19:03:31 -04:00
|
|
|
cons_show("/tiny can only be used in chat windows");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
if (!tinyurl_valid(url)) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_vprint(window, '-', 0, NULL, 0, THEME_ERROR, "", "/tiny, badly formed URL: %s", url);
|
2015-03-16 19:03:31 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-03-16 19:03:31 -04:00
|
|
|
char *tiny = tinyurl_get(url);
|
|
|
|
if (!tiny) {
|
2015-07-29 17:48:03 -04:00
|
|
|
win_print(window, '-', 0, NULL, 0, THEME_ERROR, "", "Couldn't create tinyurl.");
|
2015-03-16 19:03:31 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
switch (window->type){
|
2015-03-16 19:03:31 -04:00
|
|
|
case WIN_CHAT:
|
|
|
|
{
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-04-29 17:59:44 -04:00
|
|
|
cl_ev_send_msg(chatwin, tiny);
|
2015-03-16 19:03:31 -04:00
|
|
|
break;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2015-03-16 19:03:31 -04:00
|
|
|
case WIN_PRIVATE:
|
|
|
|
{
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
|
|
|
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
2015-05-03 20:31:27 -04:00
|
|
|
cl_ev_send_priv_msg(privatewin, tiny);
|
2015-03-16 19:03:31 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIN_MUC:
|
|
|
|
{
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2015-05-03 20:06:12 -04:00
|
|
|
cl_ev_send_muc_msg(mucwin, tiny);
|
2015-03-16 19:03:31 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tiny);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_clear(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-11-02 16:21:52 -05:00
|
|
|
win_clear(window);
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_close(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
int index = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (args[0] == NULL) {
|
2015-04-30 16:23:43 -04:00
|
|
|
index = wins_get_current_num();
|
2013-12-15 11:10:32 -05:00
|
|
|
} else if (strcmp(args[0], "all") == 0) {
|
|
|
|
count = ui_close_all_wins();
|
|
|
|
if (count == 0) {
|
|
|
|
cons_show("No windows to close.");
|
|
|
|
} else if (count == 1) {
|
|
|
|
cons_show("Closed 1 window.");
|
|
|
|
} else {
|
|
|
|
cons_show("Closed %d windows.", count);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (strcmp(args[0], "read") == 0) {
|
|
|
|
count = ui_close_read_wins();
|
|
|
|
if (count == 0) {
|
|
|
|
cons_show("No windows to close.");
|
|
|
|
} else if (count == 1) {
|
|
|
|
cons_show("Closed 1 window.");
|
|
|
|
} else {
|
|
|
|
cons_show("Closed %d windows.", count);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
index = atoi(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index < 0 || index == 10) {
|
|
|
|
cons_show("No such window exists.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == 1) {
|
|
|
|
cons_show("Cannot close console window.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
ProfWin *toclose = wins_get_by_num(index);
|
|
|
|
if (!toclose) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Window is not open.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-15 17:31:15 -04:00
|
|
|
// check for unsaved form
|
|
|
|
if (ui_win_has_unsaved_form(index)) {
|
2015-04-30 16:23:43 -04:00
|
|
|
ui_current_print_line("You have unsaved changes, use /form submit or /form cancel");
|
2014-09-15 17:31:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
// handle leaving rooms, or chat
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
ui_close_connected_win(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// close the window
|
|
|
|
ui_close_win(index);
|
|
|
|
cons_show("Closed window %d", index);
|
|
|
|
|
2015-05-29 09:25:14 -04:00
|
|
|
// Tidy up the window list.
|
|
|
|
if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) {
|
2015-11-02 16:03:30 -05:00
|
|
|
wins_tidy();
|
2015-05-29 09:25:14 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_leave(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
2015-04-30 16:23:43 -04:00
|
|
|
int index = wins_get_current_num();
|
2013-12-15 11:10:32 -05:00
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_MUC) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("You can only use the /leave command in a chat room.");
|
|
|
|
cons_alert();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle leaving rooms, or chat
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
ui_close_connected_win(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// close the window
|
|
|
|
ui_close_win(index);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-18 15:22:34 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_privileges(ProfWin *window, const char *const command, gchar **args)
|
2014-10-18 15:22:34 -04:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "MUC privileges", PREF_MUC_PRIVILEGES);
|
2014-10-18 15:22:34 -04:00
|
|
|
|
|
|
|
ui_redraw_all_room_rosters();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_beep(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Sound", PREF_BEEP);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
2014-11-07 17:38:34 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_presence(ProfWin *window, const char *const command, gchar **args)
|
2014-11-07 17:38:34 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Contact presence", PREF_PRESENCE);
|
2014-11-07 17:38:34 -05:00
|
|
|
}
|
|
|
|
|
2014-11-09 18:29:25 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_wrap(ProfWin *window, const char *const command, gchar **args)
|
2014-11-09 18:29:25 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "Word wrap", PREF_WRAP);
|
2014-11-09 18:29:25 -05:00
|
|
|
|
|
|
|
wins_resize_all();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-11-15 19:40:54 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_time(ProfWin *window, const char *const command, gchar **args)
|
2014-11-15 19:40:54 -05:00
|
|
|
{
|
2015-09-29 18:30:23 -04:00
|
|
|
if (g_strcmp0(args[0], "lastactivity") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
2015-09-30 17:34:27 -04:00
|
|
|
cons_show("Last activity time format: '%s'.", prefs_get_string(PREF_TIME_LASTACTIVITY));
|
2015-09-29 18:30:23 -04:00
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_LASTACTIVITY, args[2]);
|
|
|
|
cons_show("Last activity time format set to '%s'.", args[2]);
|
|
|
|
ui_redraw();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
cons_show("Last activity time cannot be disabled.");
|
|
|
|
ui_redraw();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(args[0], "statusbar") == 0) {
|
2015-05-29 20:53:37 -04:00
|
|
|
if (args[1] == NULL) {
|
2015-09-30 17:34:27 -04:00
|
|
|
cons_show("Status bar time format: '%s'.", prefs_get_string(PREF_TIME_STATUSBAR));
|
2015-03-10 19:35:08 -04:00
|
|
|
return TRUE;
|
2015-05-29 20:53:37 -04:00
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_STATUSBAR, args[2]);
|
|
|
|
cons_show("Status bar time format set to '%s'.", args[2]);
|
2015-03-10 19:35:08 -04:00
|
|
|
ui_redraw();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
2015-09-30 17:34:27 -04:00
|
|
|
prefs_set_string(PREF_TIME_STATUSBAR, "off");
|
2015-03-10 19:35:08 -04:00
|
|
|
cons_show("Status bar time display disabled.");
|
|
|
|
ui_redraw();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-03-10 19:35:08 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-09-30 17:34:27 -04:00
|
|
|
} else if (g_strcmp0(args[0], "console") == 0) {
|
2015-05-29 20:53:37 -04:00
|
|
|
if (args[1] == NULL) {
|
2015-09-30 17:34:27 -04:00
|
|
|
cons_show("Console time format: '%s'.", prefs_get_string(PREF_TIME_CONSOLE));
|
2015-03-10 19:35:08 -04:00
|
|
|
return TRUE;
|
2015-05-29 20:53:37 -04:00
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
2015-09-30 17:34:27 -04:00
|
|
|
prefs_set_string(PREF_TIME_CONSOLE, args[2]);
|
|
|
|
cons_show("Console time format set to '%s'.", args[2]);
|
2015-03-10 19:35:08 -04:00
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
2015-05-29 20:53:37 -04:00
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
2015-09-30 17:34:27 -04:00
|
|
|
prefs_set_string(PREF_TIME_CONSOLE, "off");
|
|
|
|
cons_show("Console time display disabled.");
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(args[0], "chat") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("Chat time format: '%s'.", prefs_get_string(PREF_TIME_CHAT));
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_CHAT, args[2]);
|
|
|
|
cons_show("Chat time format set to '%s'.", args[2]);
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_TIME_CHAT, "off");
|
|
|
|
cons_show("Chat time display disabled.");
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(args[0], "muc") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("MUC time format: '%s'.", prefs_get_string(PREF_TIME_MUC));
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_MUC, args[2]);
|
|
|
|
cons_show("MUC time format set to '%s'.", args[2]);
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_TIME_MUC, "off");
|
|
|
|
cons_show("MUC time display disabled.");
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(args[0], "mucconfig") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("MUC config time format: '%s'.", prefs_get_string(PREF_TIME_MUCCONFIG));
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_MUCCONFIG, args[2]);
|
|
|
|
cons_show("MUC config time format set to '%s'.", args[2]);
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_TIME_MUCCONFIG, "off");
|
|
|
|
cons_show("MUC config time display disabled.");
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(args[0], "private") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("Private chat time format: '%s'.", prefs_get_string(PREF_TIME_PRIVATE));
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_PRIVATE, args[2]);
|
|
|
|
cons_show("Private chat time format set to '%s'.", args[2]);
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_TIME_PRIVATE, "off");
|
|
|
|
cons_show("Private chat time display disabled.");
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(args[0], "xml") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_show("XML Console time format: '%s'.", prefs_get_string(PREF_TIME_XMLCONSOLE));
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
|
|
|
prefs_set_string(PREF_TIME_XMLCONSOLE, args[2]);
|
|
|
|
cons_show("XML Console time format set to '%s'.", args[2]);
|
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_TIME_XMLCONSOLE, "off");
|
|
|
|
cons_show("XML Console time display disabled.");
|
2015-03-10 19:35:08 -04:00
|
|
|
wins_resize_all();
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-03-10 19:35:08 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-05-29 20:53:37 -04:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-05-29 20:53:37 -04:00
|
|
|
return TRUE;
|
2014-11-15 19:40:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_states(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "Sending chat states",
|
2013-12-15 11:10:32 -05:00
|
|
|
PREF_STATES);
|
|
|
|
|
|
|
|
// if disabled, disable outtype and gone
|
|
|
|
if (result == TRUE && (strcmp(args[0], "off") == 0)) {
|
|
|
|
prefs_set_boolean(PREF_OUTTYPE, FALSE);
|
|
|
|
prefs_set_gone(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_titlebar(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-01-11 20:12:42 -05:00
|
|
|
if (g_strcmp0(args[0], "show") != 0 && g_strcmp0(args[0], "goodbye") != 0) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-01-11 19:43:42 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-01-11 20:12:42 -05:00
|
|
|
if (g_strcmp0(args[0], "show") == 0 && g_strcmp0(args[1], "off") == 0) {
|
2014-04-03 16:46:43 -04:00
|
|
|
ui_clear_win_title();
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2015-01-11 20:12:42 -05:00
|
|
|
if (g_strcmp0(args[0], "show") == 0) {
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[1], command, "Titlebar show", PREF_TITLEBAR_SHOW);
|
2015-01-11 20:12:42 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[1], command, "Titlebar goodbye", PREF_TITLEBAR_GOODBYE);
|
2015-01-11 20:12:42 -05:00
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_outtype(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command,
|
2013-12-15 11:10:32 -05:00
|
|
|
"Sending typing notifications", PREF_OUTTYPE);
|
|
|
|
|
|
|
|
// if enabled, enable states
|
|
|
|
if (result == TRUE && (strcmp(args[0], "on") == 0)) {
|
|
|
|
prefs_set_boolean(PREF_STATES, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_gone(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *value = args[0];
|
|
|
|
|
|
|
|
gint period = atoi(value);
|
|
|
|
prefs_set_gone(period);
|
|
|
|
if (period == 0) {
|
|
|
|
cons_show("Automatic leaving conversations after period disabled.");
|
|
|
|
} else if (period == 1) {
|
|
|
|
cons_show("Leaving conversations after 1 minute of inactivity.");
|
|
|
|
} else {
|
|
|
|
cons_show("Leaving conversations after %d minutes of inactivity.", period);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if enabled, enable states
|
|
|
|
if (period > 0) {
|
|
|
|
prefs_set_boolean(PREF_STATES, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_notify(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *kind = args[0];
|
|
|
|
|
|
|
|
// bad kind
|
|
|
|
if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) &&
|
|
|
|
(strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0) &&
|
2014-05-24 10:54:10 -04:00
|
|
|
(strcmp(kind, "sub") != 0) && (strcmp(kind, "room") != 0)) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
// set message setting
|
|
|
|
} else if (strcmp(kind, "message") == 0) {
|
2014-05-24 15:46:03 -04:00
|
|
|
if (strcmp(args[1], "on") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Message notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_MESSAGE, TRUE);
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "off") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Message notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_MESSAGE, FALSE);
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "current") == 0) {
|
|
|
|
if (g_strcmp0(args[2], "on") == 0) {
|
2014-05-24 16:13:33 -04:00
|
|
|
cons_show("Current window message notifications enabled.");
|
2014-05-24 15:46:03 -04:00
|
|
|
prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, TRUE);
|
|
|
|
} else if (g_strcmp0(args[2], "off") == 0) {
|
2014-05-24 16:13:33 -04:00
|
|
|
cons_show("Current window message notifications disabled.");
|
2014-05-24 15:46:03 -04:00
|
|
|
prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify message current on|off");
|
|
|
|
}
|
2014-05-24 17:14:26 -04:00
|
|
|
} else if (strcmp(args[1], "text") == 0) {
|
|
|
|
if (g_strcmp0(args[2], "on") == 0) {
|
|
|
|
cons_show("Showing text in message notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, TRUE);
|
|
|
|
} else if (g_strcmp0(args[2], "off") == 0) {
|
|
|
|
cons_show("Showing text in message notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify message text on|off");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify message on|off");
|
|
|
|
}
|
|
|
|
|
2014-05-24 10:54:10 -04:00
|
|
|
// set room setting
|
|
|
|
} else if (strcmp(kind, "room") == 0) {
|
2014-05-24 15:46:03 -04:00
|
|
|
if (strcmp(args[1], "on") == 0) {
|
2014-05-24 10:54:10 -04:00
|
|
|
cons_show("Chat room notifications enabled.");
|
2014-05-24 11:46:05 -04:00
|
|
|
prefs_set_string(PREF_NOTIFY_ROOM, "on");
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "off") == 0) {
|
2014-05-24 10:54:10 -04:00
|
|
|
cons_show("Chat room notifications disabled.");
|
2014-05-24 11:46:05 -04:00
|
|
|
prefs_set_string(PREF_NOTIFY_ROOM, "off");
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "mention") == 0) {
|
2014-05-24 16:13:33 -04:00
|
|
|
cons_show("Chat room notifications enabled on mention.");
|
2014-05-24 11:46:05 -04:00
|
|
|
prefs_set_string(PREF_NOTIFY_ROOM, "mention");
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "current") == 0) {
|
|
|
|
if (g_strcmp0(args[2], "on") == 0) {
|
2014-05-24 16:13:33 -04:00
|
|
|
cons_show("Current window chat room message notifications enabled.");
|
2014-05-24 15:46:03 -04:00
|
|
|
prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, TRUE);
|
|
|
|
} else if (g_strcmp0(args[2], "off") == 0) {
|
2014-05-24 16:13:33 -04:00
|
|
|
cons_show("Current window chat room message notifications disabled.");
|
2014-05-24 15:46:03 -04:00
|
|
|
prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify room current on|off");
|
|
|
|
}
|
2014-05-24 17:14:26 -04:00
|
|
|
} else if (strcmp(args[1], "text") == 0) {
|
|
|
|
if (g_strcmp0(args[2], "on") == 0) {
|
|
|
|
cons_show("Showing text in chat room message notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_ROOM_TEXT, TRUE);
|
|
|
|
} else if (g_strcmp0(args[2], "off") == 0) {
|
|
|
|
cons_show("Showing text in chat room message notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_ROOM_TEXT, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify room text on|off");
|
|
|
|
}
|
2014-05-24 10:54:10 -04:00
|
|
|
} else {
|
2014-05-24 11:46:05 -04:00
|
|
|
cons_show("Usage: /notify room on|off|mention");
|
2014-05-24 10:54:10 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
// set typing setting
|
|
|
|
} else if (strcmp(kind, "typing") == 0) {
|
2014-05-24 15:46:03 -04:00
|
|
|
if (strcmp(args[1], "on") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Typing notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_TYPING, TRUE);
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "off") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Typing notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_TYPING, FALSE);
|
2014-05-24 16:13:33 -04:00
|
|
|
} else if (strcmp(args[1], "current") == 0) {
|
|
|
|
if (g_strcmp0(args[2], "on") == 0) {
|
|
|
|
cons_show("Current window typing notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_TYPING_CURRENT, TRUE);
|
|
|
|
} else if (g_strcmp0(args[2], "off") == 0) {
|
|
|
|
cons_show("Current window typing notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_TYPING_CURRENT, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify typing current on|off");
|
|
|
|
}
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify typing on|off");
|
|
|
|
}
|
|
|
|
|
|
|
|
// set invite setting
|
|
|
|
} else if (strcmp(kind, "invite") == 0) {
|
2014-05-24 15:46:03 -04:00
|
|
|
if (strcmp(args[1], "on") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Chat room invite notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE);
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "off") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Chat room invite notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify invite on|off");
|
|
|
|
}
|
|
|
|
|
|
|
|
// set subscription setting
|
|
|
|
} else if (strcmp(kind, "sub") == 0) {
|
2014-05-24 15:46:03 -04:00
|
|
|
if (strcmp(args[1], "on") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Subscription notifications enabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_SUB, TRUE);
|
2014-05-24 15:46:03 -04:00
|
|
|
} else if (strcmp(args[1], "off") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Subscription notifications disabled.");
|
|
|
|
prefs_set_boolean(PREF_NOTIFY_SUB, FALSE);
|
|
|
|
} else {
|
|
|
|
cons_show("Usage: /notify sub on|off");
|
|
|
|
}
|
|
|
|
|
|
|
|
// set remind setting
|
|
|
|
} else if (strcmp(kind, "remind") == 0) {
|
2014-05-24 15:46:03 -04:00
|
|
|
gint period = atoi(args[1]);
|
2013-12-15 11:10:32 -05:00
|
|
|
prefs_set_notify_remind(period);
|
|
|
|
if (period == 0) {
|
|
|
|
cons_show("Message reminders disabled.");
|
|
|
|
} else if (period == 1) {
|
|
|
|
cons_show("Message reminder period set to 1 second.");
|
|
|
|
} else {
|
|
|
|
cons_show("Message reminder period set to %d seconds.", period);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
cons_show("Unknown command: %s.", kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-21 13:15:29 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_inpblock(ProfWin *window, const char *const command, gchar **args)
|
2014-12-21 13:15:29 -05:00
|
|
|
{
|
2015-01-12 05:32:32 -05:00
|
|
|
char *subcmd = args[0];
|
|
|
|
char *value = args[1];
|
2015-01-12 18:41:15 -05:00
|
|
|
|
|
|
|
if (g_strcmp0(subcmd, "timeout") == 0) {
|
2015-01-12 05:32:32 -05:00
|
|
|
if (value == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-01-12 05:32:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-15 21:03:20 -04:00
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &intval, 1, 1000, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
2015-01-12 05:32:32 -05:00
|
|
|
cons_show("Input blocking set to %d milliseconds.", intval);
|
|
|
|
prefs_set_inpblock(intval);
|
2015-11-01 13:56:34 -05:00
|
|
|
inp_nonblocking(FALSE);
|
2015-03-15 21:03:20 -04:00
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
2015-01-12 05:32:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2014-12-21 13:15:29 -05:00
|
|
|
}
|
2015-01-12 05:32:32 -05:00
|
|
|
|
2015-01-12 18:41:15 -05:00
|
|
|
if (g_strcmp0(subcmd, "dynamic") == 0) {
|
2015-01-12 05:32:32 -05:00
|
|
|
if (value == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-01-12 05:32:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-01-12 18:41:15 -05:00
|
|
|
if (g_strcmp0(value, "on") != 0 && g_strcmp0(value, "off") != 0) {
|
2015-01-12 05:32:32 -05:00
|
|
|
cons_show("Dynamic must be one of 'on' or 'off'");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(value, command, "Dynamic input blocking", PREF_INPBLOCK_DYNAMIC);
|
2014-12-21 13:15:29 -05:00
|
|
|
}
|
2015-01-12 05:32:32 -05:00
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-01-12 05:32:32 -05:00
|
|
|
|
2014-12-21 13:15:29 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_log(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *subcmd = args[0];
|
|
|
|
char *value = args[1];
|
|
|
|
|
|
|
|
if (strcmp(subcmd, "maxsize") == 0) {
|
2014-04-13 17:20:15 -04:00
|
|
|
if (value == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-13 17:20:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-03-15 21:03:20 -04:00
|
|
|
|
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
2013-12-15 11:10:32 -05:00
|
|
|
prefs_set_max_log_size(intval);
|
|
|
|
cons_show("Log maxinum size set to %d bytes", intval);
|
2015-03-15 21:03:20 -04:00
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
2014-04-13 15:41:11 -04:00
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
2014-04-13 15:41:11 -04:00
|
|
|
if (strcmp(subcmd, "rotate") == 0) {
|
|
|
|
if (value == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-13 15:41:11 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(value, command, "Log rotate", PREF_LOG_ROTATE);
|
2014-04-13 15:41:11 -04:00
|
|
|
}
|
|
|
|
|
2014-04-13 16:56:35 -04:00
|
|
|
if (strcmp(subcmd, "shared") == 0) {
|
|
|
|
if (value == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-13 16:56:35 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(value, command, "Shared log", PREF_LOG_SHARED);
|
2014-04-13 17:20:15 -04:00
|
|
|
log_reinit();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(subcmd, "where") == 0) {
|
|
|
|
char *logfile = get_log_file_location();
|
|
|
|
cons_show("Log file: %s", logfile);
|
|
|
|
return TRUE;
|
2014-04-13 16:56:35 -04:00
|
|
|
}
|
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-13 15:41:11 -04:00
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
/* TODO: make 'level' subcommand for debug level */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_reconnect(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *value = args[0];
|
|
|
|
|
2015-03-15 21:03:20 -04:00
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
2013-12-15 11:10:32 -05:00
|
|
|
prefs_set_reconnect(intval);
|
|
|
|
if (intval == 0) {
|
|
|
|
cons_show("Reconnect disabled.", intval);
|
|
|
|
} else {
|
|
|
|
cons_show("Reconnect interval set to %d seconds.", intval);
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-15 21:03:20 -04:00
|
|
|
cons_show(err_msg);
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-03-15 21:03:20 -04:00
|
|
|
free(err_msg);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_autoping(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *value = args[0];
|
|
|
|
|
2015-03-15 21:03:20 -04:00
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
2013-12-15 11:10:32 -05:00
|
|
|
prefs_set_autoping(intval);
|
2014-01-25 19:15:34 -05:00
|
|
|
iq_set_autoping(intval);
|
2013-12-15 11:10:32 -05:00
|
|
|
if (intval == 0) {
|
|
|
|
cons_show("Autoping disabled.", intval);
|
|
|
|
} else {
|
|
|
|
cons_show("Autoping interval set to %d seconds.", intval);
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-15 21:03:20 -04:00
|
|
|
cons_show(err_msg);
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-03-15 21:03:20 -04:00
|
|
|
free(err_msg);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-03 20:08:10 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_ping(ProfWin *window, const char *const command, gchar **args)
|
2014-09-03 20:08:10 -04:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currenlty connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iq_send_ping(args[0]);
|
|
|
|
|
|
|
|
if (args[0] == NULL) {
|
|
|
|
cons_show("Pinged server...");
|
|
|
|
} else {
|
|
|
|
cons_show("Pinged %s...", args[0]);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_autoaway(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-09-27 18:08:30 -04:00
|
|
|
if ((strcmp(args[0], "mode") != 0) && (strcmp(args[0], "time") != 0) &&
|
|
|
|
(strcmp(args[0], "message") != 0) && (strcmp(args[0], "check") != 0)) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Setting must be one of 'mode', 'time', 'message' or 'check'");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-27 18:08:30 -04:00
|
|
|
if (strcmp(args[0], "mode") == 0) {
|
|
|
|
if ((strcmp(args[1], "idle") != 0) && (strcmp(args[1], "away") != 0) &&
|
|
|
|
(strcmp(args[1], "off") != 0)) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Mode must be one of 'idle', 'away' or 'off'");
|
|
|
|
} else {
|
2015-09-27 18:08:30 -04:00
|
|
|
prefs_set_string(PREF_AUTOAWAY_MODE, args[1]);
|
|
|
|
cons_show("Auto away mode set to: %s.", args[1]);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-27 18:08:30 -04:00
|
|
|
if (strcmp(args[0], "time") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "away") == 0) {
|
|
|
|
int minutesval = 0;
|
|
|
|
char *err_msg = NULL;
|
|
|
|
gboolean res = strtoi_range(args[2], &minutesval, 1, INT_MAX, &err_msg);
|
|
|
|
if (res) {
|
|
|
|
prefs_set_autoaway_time(minutesval);
|
|
|
|
if (minutesval == 1) {
|
|
|
|
cons_show("Auto away time set to: 1 minute.");
|
|
|
|
} else {
|
|
|
|
cons_show("Auto away time set to: %d minutes.", minutesval);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "xa") == 0) {
|
|
|
|
int minutesval = 0;
|
|
|
|
char *err_msg = NULL;
|
|
|
|
gboolean res = strtoi_range(args[2], &minutesval, 0, INT_MAX, &err_msg);
|
|
|
|
if (res) {
|
|
|
|
int away_time = prefs_get_autoaway_time();
|
|
|
|
if (minutesval != 0 && minutesval <= away_time) {
|
|
|
|
cons_show("Auto xa time must be larger than auto away time.");
|
|
|
|
} else {
|
|
|
|
prefs_set_autoxa_time(minutesval);
|
|
|
|
if (minutesval == 0) {
|
|
|
|
cons_show("Auto xa time disabled.");
|
|
|
|
} else if (minutesval == 1) {
|
|
|
|
cons_show("Auto xa time set to: 1 minute.");
|
|
|
|
} else {
|
|
|
|
cons_show("Auto xa time set to: %d minutes.", minutesval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2015-03-15 21:03:20 -04:00
|
|
|
} else {
|
2015-09-27 18:08:30 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 18:08:30 -04:00
|
|
|
if (strcmp(args[0], "message") == 0) {
|
|
|
|
if (g_strcmp0(args[1], "away") == 0) {
|
|
|
|
if (strcmp(args[2], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_AUTOAWAY_MESSAGE, NULL);
|
|
|
|
cons_show("Auto away message cleared.");
|
|
|
|
} else {
|
|
|
|
prefs_set_string(PREF_AUTOAWAY_MESSAGE, args[2]);
|
|
|
|
cons_show("Auto away message set to: \"%s\".", args[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[1], "xa") == 0) {
|
|
|
|
if (strcmp(args[2], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_AUTOXA_MESSAGE, NULL);
|
|
|
|
cons_show("Auto xa message cleared.");
|
|
|
|
} else {
|
|
|
|
prefs_set_string(PREF_AUTOXA_MESSAGE, args[2]);
|
|
|
|
cons_show("Auto xa message set to: \"%s\".", args[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
} else {
|
2015-09-27 18:08:30 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 18:08:30 -04:00
|
|
|
if (strcmp(args[0], "check") == 0) {
|
|
|
|
return _cmd_set_boolean_preference(args[1], command, "Online check", PREF_AUTOAWAY_CHECK);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_priority(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *value = args[0];
|
|
|
|
|
2015-03-15 21:03:20 -04:00
|
|
|
int intval = 0;
|
|
|
|
char *err_msg = NULL;
|
2015-03-15 21:06:40 -04:00
|
|
|
gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg);
|
2015-03-15 21:03:20 -04:00
|
|
|
if (res) {
|
2013-12-15 11:10:32 -05:00
|
|
|
accounts_set_priority_all(jabber_get_account_name(), intval);
|
|
|
|
resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name());
|
2015-05-07 18:21:48 -04:00
|
|
|
cl_ev_presence_send(last_presence, jabber_get_presence_message(), 0);
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show("Priority set to %d.", intval);
|
2015-03-15 21:03:20 -04:00
|
|
|
} else {
|
|
|
|
cons_show(err_msg);
|
|
|
|
free(err_msg);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_statuses(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2014-01-18 20:25:04 -05:00
|
|
|
if (strcmp(args[0], "console") != 0 &&
|
|
|
|
strcmp(args[0], "chat") != 0 &&
|
|
|
|
strcmp(args[0], "muc") != 0) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-03-15 18:25:15 -04:00
|
|
|
return TRUE;
|
2014-01-18 20:25:04 -05:00
|
|
|
}
|
|
|
|
|
2014-03-15 18:25:15 -04:00
|
|
|
if (strcmp(args[1], "all") != 0 &&
|
|
|
|
strcmp(args[1], "online") != 0 &&
|
|
|
|
strcmp(args[1], "none") != 0) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-03-15 18:25:15 -04:00
|
|
|
return TRUE;
|
2014-01-18 20:25:04 -05:00
|
|
|
}
|
2014-01-19 11:17:34 -05:00
|
|
|
|
|
|
|
if (strcmp(args[0], "console") == 0) {
|
|
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, args[1]);
|
|
|
|
if (strcmp(args[1], "all") == 0) {
|
|
|
|
cons_show("All presence updates will appear in the console.");
|
|
|
|
} else if (strcmp(args[1], "online") == 0) {
|
|
|
|
cons_show("Only online/offline presence updates will appear in the console.");
|
|
|
|
} else {
|
|
|
|
cons_show("Presence updates will not appear in the console.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(args[0], "chat") == 0) {
|
|
|
|
prefs_set_string(PREF_STATUSES_CHAT, args[1]);
|
|
|
|
if (strcmp(args[1], "all") == 0) {
|
|
|
|
cons_show("All presence updates will appear in chat windows.");
|
|
|
|
} else if (strcmp(args[1], "online") == 0) {
|
|
|
|
cons_show("Only online/offline presence updates will appear in chat windows.");
|
|
|
|
} else {
|
|
|
|
cons_show("Presence updates will not appear in chat windows.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(args[0], "muc") == 0) {
|
2014-03-15 18:25:15 -04:00
|
|
|
prefs_set_string(PREF_STATUSES_MUC, args[1]);
|
|
|
|
if (strcmp(args[1], "all") == 0) {
|
|
|
|
cons_show("All presence updates will appear in chat room windows.");
|
|
|
|
} else if (strcmp(args[1], "online") == 0) {
|
|
|
|
cons_show("Only join/leave presence updates will appear in chat room windows.");
|
|
|
|
} else {
|
|
|
|
cons_show("Presence updates will not appear in chat room windows.");
|
|
|
|
}
|
2014-01-19 11:17:34 -05:00
|
|
|
}
|
2014-03-15 18:25:15 -04:00
|
|
|
|
2014-01-18 20:25:04 -05:00
|
|
|
return TRUE;
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_vercheck(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
int num_args = g_strv_length(args);
|
|
|
|
|
|
|
|
if (num_args == 0) {
|
|
|
|
cons_check_version(TRUE);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Version checking", PREF_VERCHECK);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 08:16:32 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_xmlconsole(ProfWin *window, const char *const command, gchar **args)
|
2014-04-15 08:16:32 -04:00
|
|
|
{
|
2015-11-01 14:26:31 -05:00
|
|
|
ProfXMLWin *xmlwin = wins_get_xmlconsole();
|
|
|
|
if (xmlwin) {
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win((ProfWin*)xmlwin);
|
2015-11-01 14:26:31 -05:00
|
|
|
} else {
|
2015-11-01 14:29:59 -05:00
|
|
|
ProfWin *window = wins_new_xmlconsole();
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win(window);
|
2014-04-15 08:16:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_flash(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Screen flash", PREF_FLASH);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_intype(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Show contact typing", PREF_INTYPE);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_splash(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Splash screen", PREF_SPLASH);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_autoconnect(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
if (strcmp(args[0], "off") == 0) {
|
|
|
|
prefs_set_string(PREF_CONNECT_ACCOUNT, NULL);
|
|
|
|
cons_show("Autoconnect account disabled.");
|
|
|
|
} else if (strcmp(args[0], "set") == 0) {
|
|
|
|
prefs_set_string(PREF_CONNECT_ACCOUNT, args[1]);
|
|
|
|
cons_show("Autoconnect account set to: %s.", args[1]);
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_chlog(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "Chat logging", PREF_CHLOG);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
// if set to off, disable history
|
|
|
|
if (result == TRUE && (strcmp(args[0], "off") == 0)) {
|
|
|
|
prefs_set_boolean(PREF_HISTORY, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_grlog(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "Groupchat logging", PREF_GRLOG);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_history(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "Chat history", PREF_HISTORY);
|
2013-12-15 11:10:32 -05:00
|
|
|
|
|
|
|
// if set to on, set chlog
|
|
|
|
if (result == TRUE && (strcmp(args[0], "on") == 0)) {
|
|
|
|
prefs_set_boolean(PREF_CHLOG, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-02 05:10:05 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_carbons(ProfWin *window, const char *const command, gchar **args)
|
2015-02-02 05:10:05 -05:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
gboolean result = _cmd_set_boolean_preference(args[0], command, "Message carbons preference", PREF_CARBONS);
|
2015-02-02 05:10:05 -05:00
|
|
|
|
2015-05-17 07:29:08 -04:00
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
// enable carbons
|
|
|
|
if (strcmp(args[0], "on") == 0) {
|
|
|
|
iq_enable_carbons();
|
|
|
|
}
|
|
|
|
else if (strcmp(args[0], "off") == 0){
|
|
|
|
iq_disable_carbons();
|
|
|
|
}
|
2015-02-02 05:10:05 -05:00
|
|
|
}
|
2015-05-17 07:29:08 -04:00
|
|
|
|
2015-02-02 05:10:05 -05:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-03-15 15:48:19 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_receipts(ProfWin *window, const char *const command, gchar **args)
|
2015-03-15 15:48:19 -04:00
|
|
|
{
|
2015-03-19 18:57:51 -04:00
|
|
|
if (g_strcmp0(args[0], "send") == 0) {
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[1], command, "Send delivery receipts", PREF_RECEIPTS_SEND);
|
2015-03-19 18:57:51 -04:00
|
|
|
} else if (g_strcmp0(args[0], "request") == 0) {
|
2015-09-09 14:31:11 -04:00
|
|
|
return _cmd_set_boolean_preference(args[1], command, "Request delivery receipts", PREF_RECEIPTS_REQUEST);
|
2015-03-19 18:57:51 -04:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-03-19 18:57:51 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-03-15 15:48:19 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_away(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
_update_presence(RESOURCE_AWAY, "away", args);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_online(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
_update_presence(RESOURCE_ONLINE, "online", args);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_dnd(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
_update_presence(RESOURCE_DND, "dnd", args);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_chat(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
_update_presence(RESOURCE_CHAT, "chat", args);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_xa(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
_update_presence(RESOURCE_XA, "xa", args);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-21 20:12:14 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_pgp(ProfWin *window, const char *const command, gchar **args)
|
2015-03-21 20:12:14 -04:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBGPGME
|
2015-06-17 19:12:01 -04:00
|
|
|
if (args[0] == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-06-17 19:12:01 -04:00
|
|
|
return TRUE;
|
2015-06-20 18:49:24 -04:00
|
|
|
}
|
|
|
|
|
2015-08-25 20:24:53 -04:00
|
|
|
if (strcmp(args[0], "char") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else if (strlen(args[1]) != 1) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else {
|
|
|
|
prefs_set_pgp_char(args[1][0]);
|
|
|
|
cons_show("PGP char set to %c.", args[1][0]);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (g_strcmp0(args[0], "log") == 0) {
|
2015-06-21 16:42:58 -04:00
|
|
|
char *choice = args[1];
|
|
|
|
if (g_strcmp0(choice, "on") == 0) {
|
|
|
|
prefs_set_string(PREF_PGP_LOG, "on");
|
|
|
|
cons_show("PGP messages will be logged as plaintext.");
|
|
|
|
if (!prefs_get_boolean(PREF_CHLOG)) {
|
|
|
|
cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(choice, "off") == 0) {
|
|
|
|
prefs_set_string(PREF_PGP_LOG, "off");
|
|
|
|
cons_show("PGP message logging disabled.");
|
|
|
|
} else if (g_strcmp0(choice, "redact") == 0) {
|
|
|
|
prefs_set_string(PREF_PGP_LOG, "redact");
|
|
|
|
cons_show("PGP messages will be logged as '[redacted]'.");
|
|
|
|
if (!prefs_get_boolean(PREF_CHLOG)) {
|
|
|
|
cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-06-21 16:42:58 -04:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-20 18:49:24 -04:00
|
|
|
if (g_strcmp0(args[0], "keys") == 0) {
|
2015-08-24 19:21:49 -04:00
|
|
|
GHashTable *keys = p_gpg_list_keys();
|
|
|
|
if (!keys || g_hash_table_size(keys) == 0) {
|
2015-03-21 21:03:06 -04:00
|
|
|
cons_show("No keys found");
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cons_show("PGP keys:");
|
2015-08-24 19:21:49 -04:00
|
|
|
GList *keylist = g_hash_table_get_keys(keys);
|
|
|
|
GList *curr = keylist;
|
2015-06-20 18:49:24 -04:00
|
|
|
while (curr) {
|
2015-08-24 19:21:49 -04:00
|
|
|
ProfPGPKey *key = g_hash_table_lookup(keys, curr->data);
|
2015-06-20 18:49:24 -04:00
|
|
|
cons_show(" %s", key->name);
|
|
|
|
cons_show(" ID : %s", key->id);
|
2015-08-29 21:12:05 -04:00
|
|
|
char *format_fp = p_gpg_format_fp_str(key->fp);
|
|
|
|
cons_show(" Fingerprint : %s", format_fp);
|
|
|
|
free(format_fp);
|
2015-08-24 19:21:49 -04:00
|
|
|
if (key->secret) {
|
|
|
|
cons_show(" Type : PUBLIC, PRIVATE");
|
|
|
|
} else {
|
|
|
|
cons_show(" Type : PUBLIC");
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
2015-03-21 20:12:14 -04:00
|
|
|
}
|
2015-08-24 19:21:49 -04:00
|
|
|
g_list_free(keylist);
|
|
|
|
p_gpg_free_keys(keys);
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-23 18:29:10 -04:00
|
|
|
if (g_strcmp0(args[0], "setkey") == 0) {
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *jid = args[1];
|
|
|
|
if (!args[1]) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-06-23 18:29:10 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *keyid = args[2];
|
|
|
|
if (!args[2]) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-06-23 18:29:10 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean res = p_gpg_addkey(jid, keyid);
|
|
|
|
if (!res) {
|
|
|
|
cons_show("Key ID not found.");
|
|
|
|
} else {
|
|
|
|
cons_show("Key %s set for %s.", keyid, jid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-25 17:45:51 -04:00
|
|
|
if (g_strcmp0(args[0], "contacts") == 0) {
|
2015-06-12 20:19:56 -04:00
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-08-25 17:45:51 -04:00
|
|
|
GHashTable *pubkeys = p_gpg_pubkeys();
|
|
|
|
GList *jids = g_hash_table_get_keys(pubkeys);
|
2015-06-20 18:49:24 -04:00
|
|
|
if (!jids) {
|
2015-08-25 17:45:51 -04:00
|
|
|
cons_show("No contacts found with PGP public keys assigned.");
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-25 17:45:51 -04:00
|
|
|
cons_show("Assigned PGP public keys:");
|
2015-06-20 18:49:24 -04:00
|
|
|
GList *curr = jids;
|
|
|
|
while (curr) {
|
|
|
|
char *jid = curr->data;
|
2015-08-25 18:04:21 -04:00
|
|
|
ProfPGPPubKeyId *pubkeyid = g_hash_table_lookup(pubkeys, jid);
|
|
|
|
if (pubkeyid->received) {
|
|
|
|
cons_show(" %s: %s (received)", jid, pubkeyid->id);
|
|
|
|
} else {
|
|
|
|
cons_show(" %s: %s (stored)", jid, pubkeyid->id);
|
|
|
|
}
|
2015-06-20 18:49:24 -04:00
|
|
|
curr = g_list_next(curr);
|
2015-03-23 20:47:13 -04:00
|
|
|
}
|
2015-06-20 18:49:24 -04:00
|
|
|
g_list_free(jids);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "libver") == 0) {
|
2015-03-21 20:29:57 -04:00
|
|
|
const char *libver = p_gpg_libver();
|
2015-06-20 18:49:24 -04:00
|
|
|
if (!libver) {
|
2015-03-21 20:29:57 -04:00
|
|
|
cons_show("Could not get libgpgme version");
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
2015-03-21 20:29:57 -04:00
|
|
|
}
|
2015-06-20 18:49:24 -04:00
|
|
|
|
|
|
|
GString *fullstr = g_string_new("Using libgpgme version ");
|
|
|
|
g_string_append(fullstr, libver);
|
|
|
|
cons_show("%s", fullstr->str);
|
|
|
|
g_string_free(fullstr, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "start") == 0) {
|
2015-06-17 20:34:27 -04:00
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You must be connected to start PGP encrpytion.");
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->type != WIN_CHAT && args[1] == NULL) {
|
2015-06-17 20:34:27 -04:00
|
|
|
cons_show("You must be in a regular chat window to start PGP encrpytion.");
|
2015-06-20 18:49:24 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfChatWin *chatwin = NULL;
|
|
|
|
|
|
|
|
if (args[1]) {
|
|
|
|
char *contact = args[1];
|
|
|
|
char *barejid = roster_barejid_from_name(contact);
|
|
|
|
if (barejid == NULL) {
|
|
|
|
barejid = contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin = wins_get_chat(barejid);
|
|
|
|
if (!chatwin) {
|
2015-10-27 19:15:28 -04:00
|
|
|
chatwin = chatwin_new(barejid);
|
2015-06-20 18:49:24 -04:00
|
|
|
}
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win((ProfWin*)chatwin);
|
2015-06-20 18:49:24 -04:00
|
|
|
} else {
|
|
|
|
chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr) {
|
2015-06-20 18:49:24 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You must end the OTR session to start PGP encryption.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->pgp_send) {
|
2015-06-20 18:49:24 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You have already started PGP encryption.");
|
|
|
|
return TRUE;
|
2015-06-17 20:34:27 -04:00
|
|
|
}
|
2015-06-20 18:49:24 -04:00
|
|
|
|
|
|
|
ProfAccount *account = accounts_get_account(jabber_get_account_name());
|
2015-08-23 17:54:41 -04:00
|
|
|
if (!p_gpg_valid_key(account->pgp_keyid)) {
|
|
|
|
ui_current_print_formatted_line('!', 0, "You must specify a valid PGP key ID for this account to start PGP encryption.");
|
2015-06-20 18:49:24 -04:00
|
|
|
account_free(account);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
account_free(account);
|
|
|
|
|
|
|
|
if (!p_gpg_available(chatwin->barejid)) {
|
|
|
|
ui_current_print_formatted_line('!', 0, "No PGP key found for %s.", chatwin->barejid);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
chatwin->pgp_send = TRUE;
|
2015-06-20 18:49:24 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "PGP encyption enabled.");
|
2015-06-21 15:20:28 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(args[0], "end") == 0) {
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->type != WIN_CHAT) {
|
|
|
|
cons_show("You must be in a regular chat window to end PGP encrpytion.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->pgp_send == FALSE) {
|
2015-06-21 15:20:28 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "PGP encryption is not currently enabled.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
chatwin->pgp_send = FALSE;
|
2015-06-21 15:20:28 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "PGP encyption disabled.");
|
|
|
|
return TRUE;
|
2015-03-21 20:12:14 -04:00
|
|
|
}
|
|
|
|
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-03-21 20:12:14 -04:00
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
cons_show("This version of Profanity has not been built with PGP support enabled");
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-15 12:19:01 -05:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_otr(ProfWin *window, const char *const command, gchar **args)
|
2013-12-15 12:19:01 -05:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBOTR
|
2014-02-15 19:04:53 -05:00
|
|
|
if (args[0] == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-02-15 19:04:53 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-25 20:24:53 -04:00
|
|
|
if (strcmp(args[0], "char") == 0) {
|
|
|
|
if (args[1] == NULL) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else if (strlen(args[1]) != 1) {
|
|
|
|
cons_bad_cmd_usage(command);
|
|
|
|
} else {
|
|
|
|
prefs_set_otr_char(args[1][0]);
|
|
|
|
cons_show("OTR char set to %c.", args[1][0]);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
} else if (strcmp(args[0], "log") == 0) {
|
2014-01-13 15:17:45 -05:00
|
|
|
char *choice = args[1];
|
|
|
|
if (g_strcmp0(choice, "on") == 0) {
|
|
|
|
prefs_set_string(PREF_OTR_LOG, "on");
|
|
|
|
cons_show("OTR messages will be logged as plaintext.");
|
|
|
|
if (!prefs_get_boolean(PREF_CHLOG)) {
|
|
|
|
cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
|
|
|
}
|
|
|
|
} else if (g_strcmp0(choice, "off") == 0) {
|
|
|
|
prefs_set_string(PREF_OTR_LOG, "off");
|
|
|
|
cons_show("OTR message logging disabled.");
|
|
|
|
} else if (g_strcmp0(choice, "redact") == 0) {
|
|
|
|
prefs_set_string(PREF_OTR_LOG, "redact");
|
|
|
|
cons_show("OTR messages will be logged as '[redacted]'.");
|
|
|
|
if (!prefs_get_boolean(PREF_CHLOG)) {
|
|
|
|
cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-01-13 15:17:45 -05:00
|
|
|
}
|
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-02-11 18:19:09 -05:00
|
|
|
} else if (strcmp(args[0], "libver") == 0) {
|
|
|
|
char *version = otr_libotr_version();
|
|
|
|
cons_show("Using libotr version %s", version);
|
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-04-19 04:00:41 -04:00
|
|
|
} else if (strcmp(args[0], "policy") == 0) {
|
2014-04-22 18:53:15 -04:00
|
|
|
if (args[1] == NULL) {
|
|
|
|
char *policy = prefs_get_string(PREF_OTR_POLICY);
|
|
|
|
cons_show("OTR policy is now set to: %s", policy);
|
2014-06-17 19:32:36 -04:00
|
|
|
prefs_free_string(policy);
|
2014-04-22 18:53:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *choice = args[1];
|
2014-05-11 13:13:04 -04:00
|
|
|
if ((g_strcmp0(choice, "manual") != 0) &&
|
|
|
|
(g_strcmp0(choice, "opportunistic") != 0) &&
|
|
|
|
(g_strcmp0(choice, "always") != 0)) {
|
2014-04-22 18:53:15 -04:00
|
|
|
cons_show("OTR policy can be set to: manual, opportunistic or always.");
|
2014-05-11 13:13:04 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *contact = args[2];
|
|
|
|
if (contact == NULL) {
|
|
|
|
prefs_set_string(PREF_OTR_POLICY, choice);
|
|
|
|
cons_show("OTR policy is now set to: %s", choice);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2014-05-11 14:32:07 -04:00
|
|
|
if (jabber_get_connection_status() != JABBER_CONNECTED) {
|
|
|
|
cons_show("You must be connected to set the OTR policy for a contact.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-05-11 13:13:04 -04:00
|
|
|
char *contact_jid = roster_barejid_from_name(contact);
|
|
|
|
if (contact_jid == NULL) {
|
|
|
|
contact_jid = contact;
|
|
|
|
}
|
|
|
|
accounts_add_otr_policy(jabber_get_account_name(), contact_jid, choice);
|
|
|
|
cons_show("OTR policy for %s set to: %s", contact_jid, choice);
|
|
|
|
return TRUE;
|
2014-04-22 18:53:15 -04:00
|
|
|
}
|
2014-01-13 15:17:45 -05:00
|
|
|
}
|
|
|
|
|
2014-01-10 15:20:38 -05:00
|
|
|
if (jabber_get_connection_status() != JABBER_CONNECTED) {
|
|
|
|
cons_show("You must be connected with an account to load OTR information.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-15 12:19:01 -05:00
|
|
|
if (strcmp(args[0], "gen") == 0) {
|
2014-01-10 15:20:38 -05:00
|
|
|
ProfAccount *account = accounts_get_account(jabber_get_account_name());
|
2014-01-11 10:48:22 -05:00
|
|
|
otr_keygen(account);
|
2014-06-26 18:55:57 -04:00
|
|
|
account_free(account);
|
2014-01-10 15:20:38 -05:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-01-11 13:29:37 -05:00
|
|
|
} else if (strcmp(args[0], "myfp") == 0) {
|
2014-02-23 15:34:27 -05:00
|
|
|
if (!otr_key_loaded()) {
|
|
|
|
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-02-23 15:34:27 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
|
|
|
char *fingerprint = otr_get_my_fingerprint();
|
|
|
|
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
|
|
|
|
free(fingerprint);
|
2014-01-11 14:10:00 -05:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-01-11 14:10:00 -05:00
|
|
|
} else if (strcmp(args[0], "theirfp") == 0) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-01-11 14:10:00 -05:00
|
|
|
ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2014-01-16 18:16:37 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-01-11 14:10:00 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
|
|
|
char *fingerprint = otr_get_their_fingerprint(chatwin->barejid);
|
|
|
|
ui_current_print_formatted_line('!', 0, "%s's OTR fingerprint: %s", chatwin->barejid, fingerprint);
|
|
|
|
free(fingerprint);
|
2014-01-10 15:20:38 -05:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-01-11 12:03:01 -05:00
|
|
|
} else if (strcmp(args[0], "start") == 0) {
|
2015-06-15 18:16:22 -04:00
|
|
|
// recipient supplied
|
2015-05-04 17:23:59 -04:00
|
|
|
if (args[1]) {
|
2014-01-13 14:12:23 -05:00
|
|
|
char *contact = args[1];
|
|
|
|
char *barejid = roster_barejid_from_name(contact);
|
|
|
|
if (barejid == NULL) {
|
|
|
|
barejid = contact;
|
|
|
|
}
|
2014-01-11 12:03:01 -05:00
|
|
|
|
2015-04-29 17:59:44 -04:00
|
|
|
ProfChatWin *chatwin = wins_get_chat(barejid);
|
|
|
|
if (!chatwin) {
|
2015-10-27 19:15:28 -04:00
|
|
|
chatwin = chatwin_new(barejid);
|
2015-04-21 18:28:52 -04:00
|
|
|
}
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win((ProfWin*)chatwin);
|
2014-01-13 14:16:46 -05:00
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->pgp_send) {
|
2015-06-21 15:13:28 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr) {
|
2014-01-16 18:16:37 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!otr_key_loaded()) {
|
|
|
|
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!otr_is_secure(barejid)) {
|
|
|
|
char *otr_query_message = otr_start_query();
|
2015-08-20 17:02:58 -04:00
|
|
|
char *id = message_send_chat_otr(barejid, otr_query_message);
|
|
|
|
free(id);
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-01-13 14:16:46 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
2015-10-27 17:23:56 -04:00
|
|
|
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// no recipient, use current chat
|
2014-01-11 12:03:01 -05:00
|
|
|
} else {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-01-13 14:12:23 -05:00
|
|
|
ui_current_print_line("You must be in a regular chat window to start an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->pgp_send) {
|
2015-06-21 15:13:28 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr) {
|
2014-01-16 18:16:37 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!otr_key_loaded()) {
|
|
|
|
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
|
|
|
return TRUE;
|
2014-01-11 12:03:01 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
|
|
|
char *otr_query_message = otr_start_query();
|
2015-08-20 17:02:58 -04:00
|
|
|
char *id = message_send_chat_otr(chatwin->barejid, otr_query_message);
|
|
|
|
free(id);
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-01-11 12:03:01 -05:00
|
|
|
}
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-01-11 18:59:20 -05:00
|
|
|
} else if (strcmp(args[0], "end") == 0) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-01-11 18:59:20 -05:00
|
|
|
ui_current_print_line("You must be in a regular chat window to use OTR.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2014-01-16 18:16:37 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-01-11 18:59:20 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
2015-10-27 17:23:56 -04:00
|
|
|
chatwin_otr_unsecured(chatwin);
|
2015-06-15 18:16:22 -04:00
|
|
|
otr_end_session(chatwin->barejid);
|
2014-01-11 18:59:20 -05:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-01-11 20:20:22 -05:00
|
|
|
} else if (strcmp(args[0], "trust") == 0) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-01-11 20:20:22 -05:00
|
|
|
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2014-01-16 18:16:37 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-01-11 20:20:22 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
2015-10-27 17:23:56 -04:00
|
|
|
chatwin_otr_trust(chatwin);
|
2015-06-15 18:16:22 -04:00
|
|
|
otr_trust(chatwin->barejid);
|
2014-01-11 20:20:22 -05:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-01-11 20:20:22 -05:00
|
|
|
} else if (strcmp(args[0], "untrust") == 0) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-01-11 20:20:22 -05:00
|
|
|
ui_current_print_line("You must be in an OTR session to untrust a recipient.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2014-01-16 18:16:37 -05:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-01-11 20:20:22 -05:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
2015-10-27 17:23:56 -04:00
|
|
|
chatwin_otr_untrust(chatwin);
|
2015-06-15 18:16:22 -04:00
|
|
|
otr_untrust(chatwin->barejid);
|
2014-01-11 20:20:22 -05:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-04-26 17:08:53 -04:00
|
|
|
} else if (strcmp(args[0], "secret") == 0) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-04-26 17:08:53 -04:00
|
|
|
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2014-04-26 17:08:53 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *secret = args[1];
|
|
|
|
if (secret == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-04-26 17:08:53 -04:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
|
|
|
otr_smp_secret(chatwin->barejid, secret);
|
2014-04-26 17:08:53 -04:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2014-04-30 18:59:40 -04:00
|
|
|
} else if (strcmp(args[0], "question") == 0) {
|
|
|
|
char *question = args[1];
|
|
|
|
char *answer = args[2];
|
|
|
|
if (question == NULL || answer == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-04-30 18:59:40 -04:00
|
|
|
return TRUE;
|
2015-06-15 18:16:22 -04:00
|
|
|
}
|
|
|
|
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2015-06-15 18:16:22 -04:00
|
|
|
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
2014-04-30 18:59:40 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2015-06-15 18:16:22 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
otr_smp_question(chatwin->barejid, question, answer);
|
|
|
|
return TRUE;
|
|
|
|
|
2014-04-30 18:59:40 -04:00
|
|
|
} else if (strcmp(args[0], "answer") == 0) {
|
2015-06-16 19:15:28 -04:00
|
|
|
if (window->type != WIN_CHAT) {
|
2014-04-30 18:59:40 -04:00
|
|
|
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:49:55 -04:00
|
|
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
2015-08-29 20:32:13 -04:00
|
|
|
if (chatwin->is_otr == FALSE) {
|
2014-04-30 18:59:40 -04:00
|
|
|
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
2014-04-30 18:59:40 -04:00
|
|
|
}
|
2015-06-15 18:16:22 -04:00
|
|
|
|
|
|
|
char *answer = args[1];
|
|
|
|
if (answer == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2015-06-15 18:16:22 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
otr_smp_answer(chatwin->barejid, answer);
|
2014-04-30 18:59:40 -04:00
|
|
|
return TRUE;
|
2014-05-11 13:13:04 -04:00
|
|
|
|
2013-12-15 12:19:01 -05:00
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 12:19:01 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#else
|
2014-01-11 21:15:16 -05:00
|
|
|
cons_show("This version of Profanity has not been built with OTR support enabled");
|
2013-12-15 12:19:01 -05:00
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-06-21 16:07:57 -04:00
|
|
|
gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
cmd_encwarn(ProfWin *window, const char *const command, gchar **args)
|
2015-06-21 16:07:57 -04:00
|
|
|
{
|
2015-07-25 21:05:53 -04:00
|
|
|
return _cmd_set_boolean_preference(args[0], command, "Encryption warning message", PREF_ENC_WARN);
|
2015-06-21 16:07:57 -04:00
|
|
|
}
|
|
|
|
|
2013-12-15 11:10:32 -05:00
|
|
|
// helper function for status change commands
|
|
|
|
static void
|
|
|
|
_update_presence(const resource_presence_t resource_presence,
|
2015-10-24 19:31:42 -04:00
|
|
|
const char *const show, gchar **args)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
char *msg = NULL;
|
|
|
|
int num_args = g_strv_length(args);
|
|
|
|
if (num_args == 1) {
|
|
|
|
msg = args[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
|
|
|
|
|
|
|
if (conn_status != JABBER_CONNECTED) {
|
|
|
|
cons_show("You are not currently connected.");
|
|
|
|
} else {
|
2015-05-07 18:21:48 -04:00
|
|
|
cl_ev_presence_send(resource_presence, msg, 0);
|
2014-04-07 15:41:06 -04:00
|
|
|
ui_update_presence(resource_presence, msg, show);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function for boolean preference commands
|
|
|
|
static gboolean
|
2015-10-24 19:31:42 -04:00
|
|
|
_cmd_set_boolean_preference(gchar *arg, const char *const command,
|
|
|
|
const char *const display, preference_t pref)
|
2013-12-15 11:10:32 -05:00
|
|
|
{
|
|
|
|
GString *enabled = g_string_new(display);
|
|
|
|
g_string_append(enabled, " enabled.");
|
|
|
|
|
|
|
|
GString *disabled = g_string_new(display);
|
|
|
|
g_string_append(disabled, " disabled.");
|
|
|
|
|
2014-01-16 17:44:23 -05:00
|
|
|
if (arg == NULL) {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2014-01-16 17:44:23 -05:00
|
|
|
} else if (strcmp(arg, "on") == 0) {
|
2013-12-15 11:10:32 -05:00
|
|
|
cons_show(enabled->str);
|
|
|
|
prefs_set_boolean(pref, TRUE);
|
|
|
|
} else if (strcmp(arg, "off") == 0) {
|
|
|
|
cons_show(disabled->str);
|
|
|
|
prefs_set_boolean(pref, FALSE);
|
|
|
|
} else {
|
2015-07-25 21:05:53 -04:00
|
|
|
cons_bad_cmd_usage(command);
|
2013-12-15 11:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free(enabled, TRUE);
|
|
|
|
g_string_free(disabled, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|