mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 21:36:21 +00:00
Added C plugin code from plugins branch
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "prof_config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@@ -58,10 +58,11 @@
|
||||
#include "xmpp/form.h"
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#ifdef HAVE_LIBOTR
|
||||
#include "plugins/plugins.h"
|
||||
#ifdef PROF_HAVE_LIBOTR
|
||||
#include "otr/otr.h"
|
||||
#endif
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
#include "pgp/gpg.h"
|
||||
#endif
|
||||
#include "profanity.h"
|
||||
@@ -1733,6 +1734,17 @@ static struct cmd_t command_defs[] =
|
||||
"/account rename me gtalk")
|
||||
},
|
||||
|
||||
{ "/plugins",
|
||||
cmd_plugins, parse_args, 0, 0, NULL,
|
||||
CMD_NOTAGS
|
||||
CMD_SYN(
|
||||
"/plugins")
|
||||
CMD_DESC(
|
||||
"Show currently installed plugins. ")
|
||||
CMD_NOARGS
|
||||
CMD_NOEXAMPLES
|
||||
},
|
||||
|
||||
{ "/prefs",
|
||||
cmd_prefs, parse_args, 0, 1, NULL,
|
||||
CMD_NOTAGS
|
||||
@@ -2641,7 +2653,7 @@ cmd_exists(char *cmd)
|
||||
}
|
||||
|
||||
void
|
||||
cmd_autocomplete_add(char *value)
|
||||
cmd_autocomplete_add(const char *const value)
|
||||
{
|
||||
if (commands_ac) {
|
||||
autocomplete_add(commands_ac, value);
|
||||
@@ -2687,7 +2699,7 @@ cmd_autocomplete_remove_form_fields(DataForm *form)
|
||||
}
|
||||
|
||||
void
|
||||
cmd_autocomplete_remove(char *value)
|
||||
cmd_autocomplete_remove(const char *const value)
|
||||
{
|
||||
if (commands_ac) {
|
||||
autocomplete_remove(commands_ac, value);
|
||||
@@ -2756,7 +2768,7 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
tlscerts_reset_ac();
|
||||
prefs_reset_boolean_choice();
|
||||
presence_reset_sub_request_search();
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
p_gpg_autocomplete_key_reset();
|
||||
#endif
|
||||
autocomplete_reset(help_ac);
|
||||
@@ -2867,6 +2879,7 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
prefs_reset_room_trigger_ac();
|
||||
win_reset_search_attempts();
|
||||
win_close_reset_search_attempts();
|
||||
plugins_reset_autocomplete();
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -2968,6 +2981,8 @@ _cmd_execute(ProfWin *window, const char *const command, const char *const inp)
|
||||
g_strfreev(args);
|
||||
return result;
|
||||
}
|
||||
} else if (plugins_run_command(inp)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
gboolean ran_alias = FALSE;
|
||||
gboolean alias_result = cmd_execute_alias(window, inp, &ran_alias);
|
||||
@@ -3128,6 +3143,11 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
}
|
||||
g_hash_table_destroy(ac_funcs);
|
||||
|
||||
result = plugins_autocomplete(input);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (g_str_has_prefix(input, "/field")) {
|
||||
result = _form_field_autocomplete(window, input);
|
||||
if (result) {
|
||||
@@ -3190,7 +3210,7 @@ _who_autocomplete(ProfWin *window, const char *const input)
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
@@ -3647,7 +3667,7 @@ _pgp_autocomplete(ProfWin *window, const char *const input)
|
||||
return found;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
gboolean result;
|
||||
gchar **args = parse_args(input, 2, 3, &result);
|
||||
if ((strncmp(input, "/pgp", 4) == 0) && (result == TRUE)) {
|
||||
@@ -4568,7 +4588,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "pgpkeyid")) == 0) {
|
||||
g_string_append(beginning, " ");
|
||||
g_string_append(beginning, args[2]);
|
||||
|
||||
@@ -47,8 +47,8 @@ void cmd_uninit(void);
|
||||
|
||||
char* cmd_autocomplete(ProfWin *window, const char *const input);
|
||||
void cmd_reset_autocomplete(ProfWin *window);
|
||||
void cmd_autocomplete_add(char *value);
|
||||
void cmd_autocomplete_remove(char *value);
|
||||
void cmd_autocomplete_add(const char *const value);
|
||||
void cmd_autocomplete_remove(const char *const value);
|
||||
void cmd_autocomplete_add_form_fields(DataForm *form);
|
||||
void cmd_autocomplete_remove_form_fields(DataForm *form);
|
||||
void cmd_alias_add(char *value);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "prof_config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -61,13 +61,14 @@
|
||||
#include "jid.h"
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifdef PROF_HAVE_LIBOTR
|
||||
#include "otr/otr.h"
|
||||
#endif
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
#include "pgp/gpg.h"
|
||||
#endif
|
||||
#include "profanity.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "tools/parser.h"
|
||||
#include "tools/tinyurl.h"
|
||||
@@ -100,12 +101,19 @@ cmd_execute_default(ProfWin *window, const char *inp)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// handle non commands in non chat windows
|
||||
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE) {
|
||||
// handle non commands in non chat or plugin windows
|
||||
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE && window->type != WIN_PLUGIN) {
|
||||
cons_show("Unknown command: %s", inp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// handle plugin window
|
||||
if (window->type == WIN_PLUGIN) {
|
||||
ProfPluginWin *pluginwin = (ProfPluginWin*)window;
|
||||
plugins_win_process_line(pluginwin->tag, inp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
if (status != JABBER_CONNECTED) {
|
||||
ui_current_print_line("You are not currently connected.");
|
||||
@@ -167,7 +175,7 @@ gboolean
|
||||
cmd_tls(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
if (g_strcmp0(args[0], "certpath") == 0) {
|
||||
#ifdef HAVE_LIBMESODE
|
||||
#ifdef PROF_HAVE_LIBMESODE
|
||||
if (g_strcmp0(args[1], "set") == 0) {
|
||||
if (args[2] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
@@ -203,7 +211,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
#endif
|
||||
} else if (g_strcmp0(args[0], "trust") == 0) {
|
||||
#ifdef HAVE_LIBMESODE
|
||||
#ifdef PROF_HAVE_LIBMESODE
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
@@ -232,7 +240,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
#endif
|
||||
} else if (g_strcmp0(args[0], "trusted") == 0) {
|
||||
#ifdef HAVE_LIBMESODE
|
||||
#ifdef PROF_HAVE_LIBMESODE
|
||||
GList *certs = tlscerts_list();
|
||||
GList *curr = certs;
|
||||
|
||||
@@ -255,7 +263,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
#endif
|
||||
} else if (g_strcmp0(args[0], "revoke") == 0) {
|
||||
#ifdef HAVE_LIBMESODE
|
||||
#ifdef PROF_HAVE_LIBMESODE
|
||||
if (args[1] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
} else {
|
||||
@@ -274,7 +282,7 @@ cmd_tls(ProfWin *window, const char *const command, gchar **args)
|
||||
} else if (g_strcmp0(args[0], "show") == 0) {
|
||||
return _cmd_set_boolean_preference(args[1], command, "TLS titlebar indicator", PREF_TLS_SHOW);
|
||||
} else if (g_strcmp0(args[0], "cert") == 0) {
|
||||
#ifdef HAVE_LIBMESODE
|
||||
#ifdef PROF_HAVE_LIBMESODE
|
||||
if (args[1]) {
|
||||
TLSCertificate *cert = tlscerts_get_trusted(args[1]);
|
||||
if (!cert) {
|
||||
@@ -654,7 +662,7 @@ cmd_account(ProfWin *window, const char *const command, gchar **args)
|
||||
}
|
||||
cons_show("");
|
||||
} else if (strcmp(property, "pgpkeyid") == 0) {
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
char *err_str = NULL;
|
||||
if (!p_gpg_valid_key(value, &err_str)) {
|
||||
cons_show("Invalid PGP key ID specified: %s, see /pgp keys", err_str);
|
||||
@@ -1886,7 +1894,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args)
|
||||
if (msg) {
|
||||
cl_ev_send_msg(chatwin, msg);
|
||||
} else {
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifdef PROF_HAVE_LIBOTR
|
||||
if (otr_is_secure(barejid)) {
|
||||
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
|
||||
}
|
||||
@@ -2774,7 +2782,7 @@ cmd_resource(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifdef PROF_HAVE_LIBOTR
|
||||
if (otr_is_secure(chatwin->barejid)) {
|
||||
cons_show("Cannot choose resource during an OTR session.");
|
||||
return TRUE;
|
||||
@@ -5602,10 +5610,31 @@ cmd_xa(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
GSList *plugins = plugins_get_list();
|
||||
|
||||
GSList *curr = plugins;
|
||||
if (curr == NULL) {
|
||||
cons_show("No plugins installed.");
|
||||
} else {
|
||||
cons_show("Installed plugins:");
|
||||
while (curr) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
char *lang = plugins_get_lang_string(plugin);
|
||||
cons_show(" %s (%s)", plugin->name, lang);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
g_slist_free(curr);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_pgp(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
#ifdef HAVE_LIBGPGME
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
if (args[0] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
@@ -5837,13 +5866,12 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_show("This version of Profanity has not been built with PGP support enabled");
|
||||
return TRUE;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_otr(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifdef PROF_HAVE_LIBOTR
|
||||
if (args[0] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
|
||||
@@ -153,6 +153,7 @@ gboolean cmd_script(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_export(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_charset(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_console(ProfWin *window, const char *const command, gchar **args);
|
||||
gboolean cmd_plugins(ProfWin *window, const char *const command, gchar **args);
|
||||
|
||||
gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user