2016-02-14 17:28:55 -05:00
|
|
|
/*
|
|
|
|
* api.c
|
2019-11-13 06:11:05 -05:00
|
|
|
* vim: expandtab:ts=4:sts=4:sw=4
|
2016-02-14 17:28:55 -05:00
|
|
|
*
|
2019-01-22 05:31:45 -05:00
|
|
|
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
2016-02-14 17:28:55 -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
|
2016-07-23 20:14:49 -04:00
|
|
|
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
2016-02-14 17:28:55 -05: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-03-26 14:51:46 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-02-14 17:28:55 -05:00
|
|
|
#include <stdlib.h>
|
2016-02-24 18:52:59 -05:00
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <assert.h>
|
2016-02-14 17:28:55 -05:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "profanity.h"
|
|
|
|
#include "log.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "common.h"
|
|
|
|
#include "config/theme.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "command/cmd_defs.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "event/server_events.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "event/client_events.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "plugins/callbacks.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "plugins/autocompleters.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "plugins/themes.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "plugins/settings.h"
|
|
|
|
#include "plugins/disco.h"
|
2016-02-14 17:28:55 -05:00
|
|
|
#include "ui/ui.h"
|
2016-07-24 10:14:46 -04:00
|
|
|
#include "ui/window_list.h"
|
2021-04-28 09:17:02 -04:00
|
|
|
#include "xmpp/roster_list.h"
|
2016-02-14 17:28:55 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
api_cons_alert(void)
|
|
|
|
{
|
2020-07-09 09:44:35 -04:00
|
|
|
cons_alert(NULL);
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-20 21:06:09 -05:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_cons_show(const char* const message)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2016-02-20 21:06:09 -05:00
|
|
|
if (message == NULL) {
|
|
|
|
log_warning("%s", "prof_cons_show failed, message is NULL");
|
|
|
|
return 0;
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
2016-02-20 21:06:09 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* parsed = str_replace(message, "\r\n", "\n");
|
2016-02-20 21:06:09 -05:00
|
|
|
cons_show("%s", parsed);
|
|
|
|
free(parsed);
|
|
|
|
|
|
|
|
return 1;
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-21 18:58:13 -05:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_cons_show_themed(const char* const group, const char* const key, const char* const def, const char* const message)
|
2016-02-21 18:58:13 -05:00
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
log_warning("%s", "prof_cons_show_themed failed, message is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* parsed = str_replace(message, "\r\n", "\n");
|
2016-02-21 18:58:13 -05:00
|
|
|
theme_item_t themeitem = plugin_themes_get(group, key, def);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* console = wins_get_console();
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println(console, themeitem, "-", "%s", parsed);
|
2016-02-21 18:58:13 -05:00
|
|
|
|
|
|
|
free(parsed);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-20 21:06:09 -05:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_cons_bad_cmd_usage(const char* const cmd)
|
2016-02-18 17:25:43 -05:00
|
|
|
{
|
2016-02-20 21:06:09 -05:00
|
|
|
if (cmd == NULL) {
|
|
|
|
log_warning("%s", "prof_cons_bad_cmd_usage failed, cmd is NULL");
|
|
|
|
return 0;
|
2016-02-18 17:25:43 -05:00
|
|
|
}
|
2016-02-20 21:06:09 -05:00
|
|
|
|
|
|
|
cons_bad_cmd_usage(cmd);
|
|
|
|
|
|
|
|
return 1;
|
2016-02-18 17:25:43 -05:00
|
|
|
}
|
|
|
|
|
2016-02-14 17:28:55 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_register_command(const char* const plugin_name, const char* command_name, int min_args, int max_args,
|
|
|
|
char** synopsis, const char* description, char* arguments[][2], char** examples,
|
|
|
|
void* callback, void (*callback_exec)(PluginCommand* command, gchar** args), void (*callback_destroy)(void* callback))
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
PluginCommand* command = malloc(sizeof(PluginCommand));
|
2016-07-03 19:41:29 -04:00
|
|
|
command->command_name = strdup(command_name);
|
2016-02-14 17:28:55 -05:00
|
|
|
command->min_args = min_args;
|
|
|
|
command->max_args = max_args;
|
|
|
|
command->callback = callback;
|
2016-07-02 20:03:05 -04:00
|
|
|
command->callback_exec = callback_exec;
|
2016-07-03 19:41:29 -04:00
|
|
|
command->callback_destroy = callback_destroy;
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
CommandHelp* help = malloc(sizeof(CommandHelp));
|
2016-02-17 20:20:17 -05:00
|
|
|
|
2016-07-03 19:41:29 -04:00
|
|
|
help->tags[0] = NULL;
|
|
|
|
|
2020-11-09 05:03:54 -05:00
|
|
|
int i;
|
2016-02-17 20:20:17 -05:00
|
|
|
for (i = 0; synopsis[i] != NULL; i++) {
|
|
|
|
help->synopsis[i] = strdup(synopsis[i]);
|
|
|
|
}
|
|
|
|
help->synopsis[i] = NULL;
|
|
|
|
|
|
|
|
help->desc = strdup(description);
|
|
|
|
for (i = 0; arguments[i][0] != NULL; i++) {
|
|
|
|
help->args[i][0] = strdup(arguments[i][0]);
|
|
|
|
help->args[i][1] = strdup(arguments[i][1]);
|
|
|
|
}
|
|
|
|
help->args[i][0] = NULL;
|
|
|
|
help->args[i][1] = NULL;
|
|
|
|
|
|
|
|
for (i = 0; examples[i] != NULL; i++) {
|
|
|
|
help->examples[i] = strdup(examples[i]);
|
|
|
|
}
|
|
|
|
help->examples[i] = NULL;
|
|
|
|
|
|
|
|
command->help = help;
|
|
|
|
|
2016-07-03 19:41:29 -04:00
|
|
|
callbacks_add_command(plugin_name, command);
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_register_timed(const char* const plugin_name, void* callback, int interval_seconds,
|
|
|
|
void (*callback_exec)(PluginTimedFunction* timed_function), void (*callback_destroy)(void* callback))
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
PluginTimedFunction* timed_function = malloc(sizeof(PluginTimedFunction));
|
2016-02-14 17:28:55 -05:00
|
|
|
timed_function->callback = callback;
|
2016-07-02 20:03:05 -04:00
|
|
|
timed_function->callback_exec = callback_exec;
|
2016-07-03 19:41:29 -04:00
|
|
|
timed_function->callback_destroy = callback_destroy;
|
2016-02-14 17:28:55 -05:00
|
|
|
timed_function->interval_seconds = interval_seconds;
|
|
|
|
timed_function->timer = g_timer_new();
|
|
|
|
|
2016-07-04 16:48:04 -04:00
|
|
|
callbacks_add_timed(plugin_name, timed_function);
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_completer_add(const char* const plugin_name, const char* key, char** items)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2016-07-05 16:46:36 -04:00
|
|
|
autocompleters_add(plugin_name, key, items);
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2016-04-07 16:25:12 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_completer_remove(const char* const plugin_name, const char* key, char** items)
|
2016-04-07 16:25:12 -04:00
|
|
|
{
|
2016-07-05 16:46:36 -04:00
|
|
|
autocompleters_remove(plugin_name, key, items);
|
2016-04-07 16:25:12 -04:00
|
|
|
}
|
|
|
|
|
2016-04-07 18:25:47 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_completer_clear(const char* const plugin_name, const char* key)
|
2016-04-07 18:25:47 -04:00
|
|
|
{
|
2016-07-05 16:46:36 -04:00
|
|
|
autocompleters_clear(plugin_name, key);
|
2016-04-07 18:25:47 -04:00
|
|
|
}
|
|
|
|
|
2016-10-10 17:28:23 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_filepath_completer_add(const char* const plugin_name, const char* prefix)
|
2016-10-10 17:28:23 -04:00
|
|
|
{
|
|
|
|
autocompleters_filepath_add(plugin_name, prefix);
|
|
|
|
}
|
|
|
|
|
2016-02-14 17:28:55 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_notify(const char* message, const char* category, int timeout_ms)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
|
|
|
notify(message, timeout_ms, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_send_line(char* line)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current = wins_get_current();
|
2016-02-14 17:28:55 -05:00
|
|
|
cmd_process_input(current, line);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char*
|
2016-02-14 17:28:55 -05:00
|
|
|
api_get_current_recipient(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current = wins_get_current();
|
2016-02-14 17:28:55 -05:00
|
|
|
if (current->type == WIN_CHAT) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)current;
|
2016-02-14 17:28:55 -05:00
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
|
|
return chatwin->barejid;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char*
|
2016-02-14 17:28:55 -05:00
|
|
|
api_get_current_muc(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current = wins_get_current();
|
2016-02-14 17:28:55 -05:00
|
|
|
if (current->type == WIN_MUC) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)current;
|
2016-02-14 17:28:55 -05:00
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
|
|
|
return mucwin->roomjid;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char*
|
2016-04-15 17:24:50 -04:00
|
|
|
api_get_current_nick(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current = wins_get_current();
|
2016-04-15 17:24:50 -04:00
|
|
|
if (current->type == WIN_MUC) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)current;
|
2016-04-15 17:24:50 -04:00
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
|
|
|
return muc_nick(mucwin->roomjid);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 09:17:02 -04:00
|
|
|
char*
|
2021-04-28 09:32:20 -04:00
|
|
|
api_get_name_from_roster(const char* barejid)
|
2021-04-28 09:17:02 -04:00
|
|
|
{
|
|
|
|
return roster_get_display_name(barejid);
|
|
|
|
}
|
|
|
|
|
2016-04-15 17:24:50 -04:00
|
|
|
char**
|
|
|
|
api_get_current_occupants(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current = wins_get_current();
|
2016-04-15 17:24:50 -04:00
|
|
|
if (current->type == WIN_MUC) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)current;
|
2016-04-15 17:24:50 -04:00
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* occupants_list = muc_roster(mucwin->roomjid);
|
|
|
|
char** result = malloc((g_list_length(occupants_list) + 1) * sizeof(char*));
|
|
|
|
GList* curr = occupants_list;
|
2016-04-15 17:24:50 -04:00
|
|
|
int i = 0;
|
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
Occupant* occupant = curr->data;
|
2016-04-15 17:24:50 -04:00
|
|
|
result[i++] = strdup(occupant->nick);
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
result[i] = NULL;
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 18:06:45 -05:00
|
|
|
int
|
|
|
|
api_current_win_is_console(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current = wins_get_current();
|
2016-02-28 18:06:45 -05:00
|
|
|
if (current && current->type == WIN_CONSOLE) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-06 18:01:16 -05:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
api_get_room_nick(const char* barejid)
|
2016-11-06 18:01:16 -05:00
|
|
|
{
|
|
|
|
return muc_nick(barejid);
|
|
|
|
}
|
|
|
|
|
2016-02-14 17:28:55 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_log_debug(const char* message)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
|
|
|
log_debug("%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_log_info(const char* message)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
|
|
|
log_info("%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_log_warning(const char* message)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
|
|
|
log_warning("%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_log_error(const char* message)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
|
|
|
log_error("%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_win_exists(const char* tag)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
|
|
|
return (wins_get_plugin(tag) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-07 15:36:25 -05:00
|
|
|
api_win_create(
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* const plugin_name,
|
|
|
|
const char* tag,
|
|
|
|
void* callback,
|
|
|
|
void (*callback_exec)(PluginWindowCallback* window_callback, const char* tag, const char* const line),
|
|
|
|
void (*callback_destroy)(void* callback))
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2016-07-11 20:51:27 -04:00
|
|
|
if (callbacks_win_exists(plugin_name, tag)) {
|
2016-07-12 19:25:45 -04:00
|
|
|
if (callback_destroy) {
|
|
|
|
callback_destroy(callback);
|
|
|
|
}
|
2016-07-11 20:51:27 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
PluginWindowCallback* window = malloc(sizeof(PluginWindowCallback));
|
2016-02-14 17:28:55 -05:00
|
|
|
window->callback = callback;
|
2016-07-02 20:03:05 -04:00
|
|
|
window->callback_exec = callback_exec;
|
|
|
|
window->callback_destroy = callback_destroy;
|
2016-07-04 17:42:15 -04:00
|
|
|
|
|
|
|
callbacks_add_window_handler(plugin_name, tag, window);
|
|
|
|
|
2016-07-11 21:16:12 -04:00
|
|
|
wins_new_plugin(plugin_name, tag);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
|
|
|
// set status bar active
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = wins_get_plugin(tag);
|
2016-02-14 17:28:55 -05:00
|
|
|
int num = wins_get_num((ProfWin*)pluginwin);
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(num, WIN_PLUGIN, pluginwin->tag);
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-20 21:06:09 -05:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_win_focus(const char* tag)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2016-02-20 21:06:09 -05:00
|
|
|
if (tag == NULL) {
|
|
|
|
log_warning("%s", "prof_win_focus failed, tag is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = wins_get_plugin(tag);
|
2016-02-20 21:06:09 -05:00
|
|
|
if (pluginwin == NULL) {
|
|
|
|
log_warning("prof_win_focus failed, no window with tag: %s", tag);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-14 17:28:55 -05:00
|
|
|
ui_focus_win((ProfWin*)pluginwin);
|
2016-02-20 21:06:09 -05:00
|
|
|
|
|
|
|
return 1;
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-20 21:06:09 -05:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_win_show(const char* tag, const char* line)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2016-02-20 21:06:09 -05:00
|
|
|
if (tag == NULL) {
|
|
|
|
log_warning("%s", "prof_win_show failed, tag is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (line == NULL) {
|
|
|
|
log_warning("%s", "prof_win_show failed, line is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = wins_get_plugin(tag);
|
2016-02-20 21:06:09 -05:00
|
|
|
if (pluginwin == NULL) {
|
|
|
|
log_warning("prof_win_show failed, no window with tag: %s", tag);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = (ProfWin*)pluginwin;
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println(window, THEME_DEFAULT, "!", "%s", line);
|
2016-02-20 21:06:09 -05:00
|
|
|
|
|
|
|
return 1;
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-20 21:06:09 -05:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_win_show_themed(const char* tag, const char* const group, const char* const key, const char* const def, const char* line)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2016-02-20 21:06:09 -05:00
|
|
|
if (tag == NULL) {
|
2016-02-21 18:58:13 -05:00
|
|
|
log_warning("%s", "prof_win_show_themed failed, tag is NULL");
|
2016-02-20 21:06:09 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (line == NULL) {
|
2016-02-21 18:58:13 -05:00
|
|
|
log_warning("%s", "prof_win_show_themed failed, line is NULL");
|
2016-02-20 21:06:09 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = wins_get_plugin(tag);
|
2016-02-20 21:06:09 -05:00
|
|
|
if (pluginwin == NULL) {
|
2016-02-21 18:58:13 -05:00
|
|
|
log_warning("prof_win_show_themed failed, no window with tag: %s", tag);
|
2016-02-20 21:06:09 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-21 18:58:13 -05:00
|
|
|
theme_item_t themeitem = plugin_themes_get(group, key, def);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = (ProfWin*)pluginwin;
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println(window, themeitem, "!", "%s", line);
|
2016-02-20 21:06:09 -05:00
|
|
|
|
|
|
|
return 1;
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
2016-03-23 18:57:03 -04:00
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_send_stanza(const char* const stanza)
|
2016-03-23 18:57:03 -04:00
|
|
|
{
|
2016-05-05 20:51:58 -04:00
|
|
|
return connection_send_stanza(stanza);
|
2016-03-23 18:57:03 -04:00
|
|
|
}
|
|
|
|
|
2016-03-25 18:06:24 -04:00
|
|
|
gboolean
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_boolean_get(const char* const group, const char* const key, gboolean def)
|
2016-03-25 18:06:24 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
return plugin_settings_boolean_get(group, key, def);
|
2016-03-25 18:06:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_boolean_set(const char* const group, const char* const key, gboolean value)
|
2016-03-25 18:06:24 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
plugin_settings_boolean_set(group, key, value);
|
2016-03-25 18:06:24 -04:00
|
|
|
}
|
2016-03-25 21:48:42 -04:00
|
|
|
|
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_string_get(const char* const group, const char* const key, const char* const def)
|
2016-03-25 21:48:42 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
return plugin_settings_string_get(group, key, def);
|
2016-03-25 21:48:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_string_set(const char* const group, const char* const key, const char* const value)
|
2016-03-25 21:48:42 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
plugin_settings_string_set(group, key, value);
|
2016-03-25 21:48:42 -04:00
|
|
|
}
|
2016-03-25 22:19:30 -04:00
|
|
|
|
2016-08-01 16:34:38 -04:00
|
|
|
char**
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_string_list_get(const char* const group, const char* const key)
|
2016-08-01 16:34:38 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
return plugin_settings_string_list_get(group, key);
|
2016-08-01 16:34:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_string_list_add(const char* const group, const char* const key, const char* const value)
|
2016-08-01 16:34:38 -04:00
|
|
|
{
|
|
|
|
plugin_settings_string_list_add(group, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_string_list_remove(const char* const group, const char* const key, const char* const value)
|
2016-08-01 16:34:38 -04:00
|
|
|
{
|
|
|
|
return plugin_settings_string_list_remove(group, key, value);
|
|
|
|
}
|
|
|
|
|
2016-08-01 17:09:25 -04:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_string_list_clear(const char* const group, const char* const key)
|
2016-08-01 16:34:38 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
return plugin_settings_string_list_clear(group, key);
|
2016-08-01 16:34:38 -04:00
|
|
|
}
|
|
|
|
|
2016-03-25 22:19:30 -04:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_int_get(const char* const group, const char* const key, int def)
|
2016-03-25 22:19:30 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
return plugin_settings_int_get(group, key, def);
|
2016-03-25 22:19:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_settings_int_set(const char* const group, const char* const key, int value)
|
2016-03-25 22:19:30 -04:00
|
|
|
{
|
2016-08-06 19:16:57 -04:00
|
|
|
plugin_settings_int_set(group, key, value);
|
2016-03-25 22:19:30 -04:00
|
|
|
}
|
2016-03-29 18:44:54 -04:00
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_incoming_message(const char* const barejid, const char* const resource, const char* const plain)
|
2016-03-29 18:44:54 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessage* message = message_init();
|
2020-04-11 11:11:53 -04:00
|
|
|
message->from_jid = jid_create_from_bare_and_resource(barejid, resource);
|
2019-06-17 00:23:40 -04:00
|
|
|
message->plain = strdup(plain);
|
|
|
|
|
|
|
|
sv_ev_incoming_message(message);
|
2016-03-29 18:44:54 -04:00
|
|
|
|
|
|
|
// TODO handle all states
|
|
|
|
sv_ev_activity((char*)barejid, (char*)resource, FALSE);
|
2019-06-17 00:23:40 -04:00
|
|
|
|
|
|
|
message_free(message);
|
2016-03-29 18:44:54 -04:00
|
|
|
}
|
2016-04-30 18:00:07 -04:00
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_disco_add_feature(char* plugin_name, char* feature)
|
2016-04-30 18:00:07 -04:00
|
|
|
{
|
|
|
|
if (feature == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_disco_add_feature failed, feature is NULL");
|
2016-04-30 18:00:07 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:20:59 -04:00
|
|
|
disco_add_feature(plugin_name, feature);
|
|
|
|
|
2016-04-30 18:00:07 -04:00
|
|
|
caps_reset_ver();
|
|
|
|
|
|
|
|
// resend presence to update server's disco info data for this client
|
2016-05-05 18:51:49 -04:00
|
|
|
if (connection_get_status() == JABBER_CONNECTED) {
|
2016-05-05 19:53:03 -04:00
|
|
|
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
|
2017-01-15 18:59:31 -05:00
|
|
|
cl_ev_presence_send(last_presence, 0);
|
2016-04-30 18:00:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 17:46:29 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
api_encryption_reset(const char* const barejid)
|
2017-01-18 17:46:29 -05:00
|
|
|
{
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_encryption_reset failed, barejid is NULL");
|
2017-01-18 17:46:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-18 17:46:29 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_encryption_reset failed, could not find chat window for %s", barejid);
|
2017-01-18 17:46:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-18 18:16:23 -05:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2017-01-18 17:46:29 -05:00
|
|
|
if (chatwin->pgp_send) {
|
|
|
|
chatwin->pgp_send = FALSE;
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "PGP encryption disabled.");
|
2017-01-18 17:46:29 -05:00
|
|
|
}
|
2017-01-18 18:16:23 -05:00
|
|
|
#endif
|
2017-01-18 17:46:29 -05:00
|
|
|
|
2017-01-18 18:16:23 -05:00
|
|
|
#ifdef HAVE_LIBOTR
|
2017-01-18 17:46:29 -05:00
|
|
|
if (chatwin->is_otr) {
|
|
|
|
chatwin_otr_unsecured(chatwin);
|
|
|
|
otr_end_session(chatwin->barejid);
|
|
|
|
}
|
2017-01-18 18:16:23 -05:00
|
|
|
#endif
|
2017-01-18 17:46:29 -05:00
|
|
|
}
|
2017-01-19 17:33:29 -05:00
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_set_titlebar_enctext(const char* const barejid, const char* const enctext)
|
2017-01-19 17:33:29 -05:00
|
|
|
{
|
|
|
|
if (enctext == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_titlebar_enctext failed, enctext is NULL");
|
2017-01-19 17:33:29 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_titlebar_enctext failed, barejid is NULL");
|
2017-01-19 17:33:29 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-19 17:33:29 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_titlebar_enctext failed, could not find chat window for %s", barejid);
|
2017-01-19 17:33:29 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin_set_enctext(chatwin, enctext);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_unset_titlebar_enctext(const char* const barejid)
|
2017-01-19 17:33:29 -05:00
|
|
|
{
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_unset_titlebar_enctext failed, barejid is NULL");
|
2017-01-19 17:33:29 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-19 17:33:29 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_unset_titlebar_enctext failed, could not find chat window for %s", barejid);
|
2017-01-19 17:33:29 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin_unset_enctext(chatwin);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2017-01-20 16:03:55 -05:00
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_set_incoming_char(const char* const barejid, const char* const ch)
|
2017-01-20 16:03:55 -05:00
|
|
|
{
|
|
|
|
if (ch == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_incoming_char failed, ch is NULL");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(ch) != 1) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_incoming_char failed, ch must be a string of length 1");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_incoming_char failed, barejid is NULL");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_incoming_char failed, could not find chat window for %s", barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin_set_incoming_char(chatwin, ch);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_unset_incoming_char(const char* const barejid)
|
2017-01-20 16:03:55 -05:00
|
|
|
{
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_unset_incoming_char failed, barejid is NULL");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_unset_incoming_char failed, could not find chat window for %s", barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin_unset_incoming_char(chatwin);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_set_outgoing_char(const char* const barejid, const char* const ch)
|
2017-01-20 16:03:55 -05:00
|
|
|
{
|
|
|
|
if (ch == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_outgoing_char failed, ch is NULL");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(ch) != 1) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_outgoing_char failed, ch must be a string of length 1");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_outgoing_char failed, barejid is NULL");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_set_outgoing_char failed, could not find chat window for %s", barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin_set_outgoing_char(chatwin, ch);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_unset_outgoing_char(const char* const barejid)
|
2017-01-20 16:03:55 -05:00
|
|
|
{
|
|
|
|
if (barejid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_unset_outgoing_char failed, barejid is NULL");
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
if (chatwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_unset_outgoing_char failed, could not find chat window for %s", barejid);
|
2017-01-20 16:03:55 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chatwin_unset_outgoing_char(chatwin);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2017-01-20 18:26:14 -05:00
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_room_set_titlebar_enctext(const char* const roomjid, const char* const enctext)
|
2017-01-20 18:26:14 -05:00
|
|
|
{
|
|
|
|
if (enctext == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_set_titlebar_enctext failed, enctext is NULL");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (roomjid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_set_titlebar_enctext failed, roomjid is NULL");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
if (mucwin == NULL) {
|
2020-12-10 03:24:32 -05:00
|
|
|
log_warning("%s", "api_room_set_titlebar_enctext failed, could not find room window for %s", roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mucwin_set_enctext(mucwin, enctext);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_room_unset_titlebar_enctext(const char* const roomjid)
|
2017-01-20 18:26:14 -05:00
|
|
|
{
|
|
|
|
if (roomjid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_unset_titlebar_enctext failed, roomjid is NULL");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
if (mucwin == NULL) {
|
2020-12-10 03:24:32 -05:00
|
|
|
log_warning("%s", "api_room_unset_titlebar_enctext failed, could not find room window for %s", roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mucwin_unset_enctext(mucwin);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_room_set_message_char(const char* const roomjid, const char* const ch)
|
2017-01-20 18:26:14 -05:00
|
|
|
{
|
|
|
|
if (ch == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_set_message_char failed, ch is NULL");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(ch) != 1) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_set_message_char failed, ch must be a string of length 1");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (roomjid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_set_message_char failed, roomjid is NULL");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
if (mucwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_set_message_char failed, could not find room window for %s", roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mucwin_set_message_char(mucwin, ch);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_room_unset_message_char(const char* const roomjid)
|
2017-01-20 18:26:14 -05:00
|
|
|
{
|
|
|
|
if (roomjid == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_unset_message_char failed, roomjid is NULL");
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
if (mucwin == NULL) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_unset_message_char failed, could not find room window for %s", roomjid);
|
2017-01-20 18:26:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mucwin_unset_message_char(mucwin);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2017-01-21 15:23:28 -05:00
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_show(const char* const barejid, const char* message)
|
2017-01-21 15:23:28 -05:00
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
log_warning("%s", "api_chat_show failed, message is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (barejid == NULL) {
|
|
|
|
log_warning("%s", "api_chat_show failed, barejid is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-21 15:23:28 -05:00
|
|
|
if (chatwin == NULL) {
|
|
|
|
log_warning("%s", "api_chat_show failed, could not find chat window for %s", barejid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* parsed = str_replace(message, "\r\n", "\n");
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println((ProfWin*)chatwin, THEME_TEXT, "-", "%s", parsed);
|
2017-01-21 15:23:28 -05:00
|
|
|
free(parsed);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_chat_show_themed(const char* const barejid, const char* const group, const char* const key, const char* const def,
|
|
|
|
const char* const ch, const char* const message)
|
2017-01-21 15:23:28 -05:00
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
log_warning("%s", "api_chat_show_themed failed, message is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (barejid == NULL) {
|
|
|
|
log_warning("%s", "api_chat_show_themed failed, barejid is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* show_ch = "-";
|
2017-01-21 15:23:28 -05:00
|
|
|
if (ch) {
|
2020-02-20 12:11:08 -05:00
|
|
|
if (g_utf8_strlen(ch, 4) != 1) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_chat_show_themed failed, ch must be a string of length 1");
|
|
|
|
return 0;
|
|
|
|
} else {
|
2020-02-20 12:11:08 -05:00
|
|
|
show_ch = (char*)ch;
|
2017-01-21 15:23:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2017-01-21 15:23:28 -05:00
|
|
|
if (chatwin == NULL) {
|
|
|
|
log_warning("%s", "api_chat_show_themed failed, could not find chat window for %s", barejid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* parsed = str_replace(message, "\r\n", "\n");
|
2017-01-21 15:23:28 -05:00
|
|
|
theme_item_t themeitem = plugin_themes_get(group, key, def);
|
|
|
|
|
|
|
|
win_println((ProfWin*)chatwin, themeitem, show_ch, "%s", parsed);
|
|
|
|
free(parsed);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_room_show(const char* const roomjid, const char* message)
|
2017-01-21 15:23:28 -05:00
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
log_warning("%s", "api_room_show failed, message is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (roomjid == NULL) {
|
|
|
|
log_warning("%s", "api_room_show failed, roomjid is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
2017-01-21 15:23:28 -05:00
|
|
|
if (mucwin == NULL) {
|
|
|
|
log_warning("%s", "api_room_show failed, could not find room window for %s", roomjid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* parsed = str_replace(message, "\r\n", "\n");
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println((ProfWin*)mucwin, THEME_TEXT, "-", "%s", parsed);
|
2017-01-21 15:23:28 -05:00
|
|
|
free(parsed);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
api_room_show_themed(const char* const roomjid, const char* const group, const char* const key, const char* const def,
|
|
|
|
const char* const ch, const char* const message)
|
2017-01-21 15:23:28 -05:00
|
|
|
{
|
|
|
|
if (message == NULL) {
|
|
|
|
log_warning("%s", "api_room_show_themed failed, message is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (roomjid == NULL) {
|
|
|
|
log_warning("%s", "api_room_show_themed failed, roomjid is NULL");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* show_ch = "-";
|
2017-01-21 15:23:28 -05:00
|
|
|
if (ch) {
|
2020-02-20 12:11:08 -05:00
|
|
|
if (g_utf8_strlen(ch, 4) != 1) {
|
2017-01-21 15:23:28 -05:00
|
|
|
log_warning("%s", "api_room_show_themed failed, ch must be a string of length 1");
|
|
|
|
return 0;
|
|
|
|
} else {
|
2020-02-20 12:11:08 -05:00
|
|
|
show_ch = (char*)ch;
|
2017-01-21 15:23:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
2017-01-21 15:23:28 -05:00
|
|
|
if (mucwin == NULL) {
|
|
|
|
log_warning("%s", "api_room_show_themed failed, could not find room window for %s", roomjid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* parsed = str_replace(message, "\r\n", "\n");
|
2017-01-21 15:23:28 -05:00
|
|
|
theme_item_t themeitem = plugin_themes_get(group, key, def);
|
|
|
|
|
|
|
|
win_println((ProfWin*)mucwin, themeitem, show_ch, "%s", parsed);
|
|
|
|
free(parsed);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|