mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-19 11:56:22 +00:00
Add chat and room show calls to plugins api
This commit is contained in:
@@ -483,6 +483,7 @@ void
|
||||
api_disco_add_feature(char *plugin_name, char *feature)
|
||||
{
|
||||
if (feature == NULL) {
|
||||
log_warning("%s", "api_disco_add_feature failed, feature is NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -501,11 +502,13 @@ void
|
||||
api_encryption_reset(const char *const barejid)
|
||||
{
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_encryption_reset failed, barejid is NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_encryption_reset failed, could not find chat window for %s", barejid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -528,15 +531,18 @@ int
|
||||
api_chat_set_titlebar_enctext(const char *const barejid, const char *const enctext)
|
||||
{
|
||||
if (enctext == NULL) {
|
||||
log_warning("%s", "api_chat_set_titlebar_enctext failed, enctext is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_chat_set_titlebar_enctext failed, barejid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_set_titlebar_enctext failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -549,11 +555,13 @@ int
|
||||
api_chat_unset_titlebar_enctext(const char *const barejid)
|
||||
{
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_chat_unset_titlebar_enctext failed, barejid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_unset_titlebar_enctext failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -566,19 +574,23 @@ int
|
||||
api_chat_set_incoming_char(const char *const barejid, const char *const ch)
|
||||
{
|
||||
if (ch == NULL) {
|
||||
log_warning("%s", "api_chat_set_incoming_char failed, ch is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(ch) != 1) {
|
||||
log_warning("%s", "api_chat_set_incoming_char failed, ch must be a string of length 1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_chat_set_incoming_char failed, barejid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_set_incoming_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -591,11 +603,13 @@ int
|
||||
api_chat_unset_incoming_char(const char *const barejid)
|
||||
{
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_chat_unset_incoming_char failed, barejid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_unset_incoming_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -608,19 +622,23 @@ int
|
||||
api_chat_set_outgoing_char(const char *const barejid, const char *const ch)
|
||||
{
|
||||
if (ch == NULL) {
|
||||
log_warning("%s", "api_chat_set_outgoing_char failed, ch is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(ch) != 1) {
|
||||
log_warning("%s", "api_chat_set_outgoing_char failed, ch must be a string of length 1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_chat_set_outgoing_char failed, barejid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_set_outgoing_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -633,11 +651,13 @@ int
|
||||
api_chat_unset_outgoing_char(const char *const barejid)
|
||||
{
|
||||
if (barejid == NULL) {
|
||||
log_warning("%s", "api_chat_unset_outgoing_char failed, barejid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_unset_outgoing_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -650,15 +670,18 @@ int
|
||||
api_room_set_titlebar_enctext(const char *const roomjid, const char *const enctext)
|
||||
{
|
||||
if (enctext == NULL) {
|
||||
log_warning("%s", "api_room_set_titlebar_enctext failed, enctext is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (roomjid == NULL) {
|
||||
log_warning("%s", "api_room_set_titlebar_enctext failed, roomjid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("%s", "api_room_set_titlebar_enctext failed, coudl not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -671,11 +694,13 @@ int
|
||||
api_room_unset_titlebar_enctext(const char *const roomjid)
|
||||
{
|
||||
if (roomjid == NULL) {
|
||||
log_warning("%s", "api_room_unset_titlebar_enctext failed, roomjid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("%s", "api_room_unset_titlebar_enctext failed, coudl not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -688,19 +713,23 @@ int
|
||||
api_room_set_message_char(const char *const roomjid, const char *const ch)
|
||||
{
|
||||
if (ch == NULL) {
|
||||
log_warning("%s", "api_room_set_message_char failed, ch is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(ch) != 1) {
|
||||
log_warning("%s", "api_room_set_message_char failed, ch must be a string of length 1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (roomjid == NULL) {
|
||||
log_warning("%s", "api_room_set_message_char failed, roomjid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("%s", "api_room_set_message_char failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -713,11 +742,13 @@ int
|
||||
api_room_unset_message_char(const char *const roomjid)
|
||||
{
|
||||
if (roomjid == NULL) {
|
||||
log_warning("%s", "api_room_unset_message_char failed, roomjid is NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("%s", "api_room_unset_message_char failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -725,3 +756,133 @@ api_room_unset_message_char(const char *const roomjid)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
api_chat_show(const char *const barejid, const char *message)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_show failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *parsed = str_replace(message, "\r\n", "\n");
|
||||
win_println((ProfWin*)chatwin, THEME_TEXT, '-', "%s", parsed);
|
||||
free(parsed);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
char show_ch = '-';
|
||||
if (ch) {
|
||||
if (strlen(ch) != 1) {
|
||||
log_warning("%s", "api_chat_show_themed failed, ch must be a string of length 1");
|
||||
return 0;
|
||||
} else {
|
||||
show_ch = ch[0];
|
||||
}
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("%s", "api_chat_show_themed failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *parsed = str_replace(message, "\r\n", "\n");
|
||||
theme_item_t themeitem = plugin_themes_get(group, key, def);
|
||||
|
||||
win_println((ProfWin*)chatwin, themeitem, show_ch, "%s", parsed);
|
||||
free(parsed);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
api_room_show(const char *const roomjid, const char *message)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("%s", "api_room_show failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *parsed = str_replace(message, "\r\n", "\n");
|
||||
win_println((ProfWin*)mucwin, THEME_TEXT, '-', "%s", parsed);
|
||||
free(parsed);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
char show_ch = '-';
|
||||
if (ch) {
|
||||
if (strlen(ch) != 1) {
|
||||
log_warning("%s", "api_room_show_themed failed, ch must be a string of length 1");
|
||||
return 0;
|
||||
} else {
|
||||
show_ch = ch[0];
|
||||
}
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("%s", "api_room_show_themed failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *parsed = str_replace(message, "\r\n", "\n");
|
||||
theme_item_t themeitem = plugin_themes_get(group, key, def);
|
||||
|
||||
win_println((ProfWin*)mucwin, themeitem, show_ch, "%s", parsed);
|
||||
free(parsed);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -109,4 +109,12 @@ int api_room_unset_titlebar_enctext(const char *const roomjid);
|
||||
int api_room_set_message_char(const char *const roomjid, const char *const ch);
|
||||
int api_room_unset_message_char(const char *const roomjid);
|
||||
|
||||
int api_chat_show(const char *const barejid, const char *const message);
|
||||
int 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);
|
||||
|
||||
int api_room_show(const char *const roomjid, const char *message);
|
||||
int 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);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -407,6 +407,32 @@ c_api_room_unset_message_char(const char *roomjid)
|
||||
return api_room_unset_message_char(roomjid);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_chat_show(const char *const barejid, const char *const message)
|
||||
{
|
||||
return api_chat_show(barejid, message);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_chat_show_themed(const char *const barejid, const char *const group, const char *const item, const char *const def,
|
||||
const char *const ch, const char *const message)
|
||||
{
|
||||
return api_chat_show_themed(barejid, group, item, def, ch, message);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_room_show(const char *const roomjid, const char *const message)
|
||||
{
|
||||
return api_room_show(roomjid, message);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_room_show_themed(const char *const roomjid, const char *const group, const char *const item, const char *const def,
|
||||
const char *const ch, const char *const message)
|
||||
{
|
||||
return api_room_show_themed(roomjid, group, item, def, ch, message);
|
||||
}
|
||||
|
||||
void
|
||||
c_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@@ -485,6 +511,10 @@ c_api_init(void)
|
||||
prof_room_unset_titlebar_enctext = c_api_room_unset_titlebar_enctext;
|
||||
prof_room_set_message_char = c_api_room_set_message_char;
|
||||
prof_room_unset_message_char = c_api_room_unset_message_char;
|
||||
prof_chat_show = c_api_chat_show;
|
||||
prof_chat_show_themed = c_api_chat_show_themed;
|
||||
prof_room_show = c_api_room_show;
|
||||
prof_room_show_themed = c_api_room_show_themed;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
||||
@@ -105,3 +105,11 @@ int (*prof_room_set_titlebar_enctext)(const char *roomjid, const char *enctext)
|
||||
int (*prof_room_unset_titlebar_enctext)(const char *roomjid) = NULL;
|
||||
int (*prof_room_set_message_char)(const char *roomjid, const char *ch) = NULL;
|
||||
int (*prof_room_unset_message_char)(const char *roomjid) = NULL;
|
||||
|
||||
int (*prof_chat_show)(const char *const barejid, const char *const message) = NULL;
|
||||
int (*prof_chat_show_themed)(const char *const barejid, const char *const group, const char *const item, const char *const def,
|
||||
const char *const ch, const char *const message) = NULL;
|
||||
|
||||
int (*prof_room_show)(const char *const roomjid, const char *const message) = NULL;
|
||||
int (*prof_room_show_themed)(const char *const roomjid, const char *const group, const char *const item, const char *const def,
|
||||
const char *const ch, const char *const message) = NULL;
|
||||
|
||||
@@ -118,4 +118,12 @@ int (*prof_room_unset_titlebar_enctext)(const char *roomjid);
|
||||
int (*prof_room_set_message_char)(const char *roomjid, const char *ch);
|
||||
int (*prof_room_unset_message_char)(const char *roomjid);
|
||||
|
||||
int (*prof_chat_show)(const char *const barejid, const char *const message);
|
||||
int (*prof_chat_show_themed)(const char *const barejid, const char *const group, const char *const item, const char *const def,
|
||||
const char *const ch, const char *const message);
|
||||
|
||||
int (*prof_room_show)(const char *const roomjid, const char *const message);
|
||||
int (*prof_room_show_themed)(const char *const roomjid, const char *const group, const char *const item, const char *const def,
|
||||
const char *const ch, const char *const message);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1284,6 +1284,130 @@ python_api_room_unset_message_char(PyObject *self, PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_chat_show(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *barejid = NULL;
|
||||
PyObject *message = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OO", &barejid, &message)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
char *message_str = python_str_or_unicode_to_string(message);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_chat_show(barejid_str, message_str);
|
||||
free(barejid_str);
|
||||
free(message_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_chat_show_themed(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *barejid = NULL;
|
||||
PyObject *group = NULL;
|
||||
PyObject *key = NULL;
|
||||
PyObject *def = NULL;
|
||||
PyObject *ch = NULL;
|
||||
PyObject *message = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OOOOOO", &barejid, &group, &key, &def, &ch, &message)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
char *group_str = python_str_or_unicode_to_string(group);
|
||||
char *key_str = python_str_or_unicode_to_string(key);
|
||||
char *def_str = python_str_or_unicode_to_string(def);
|
||||
char *ch_str = python_str_or_unicode_to_string(ch);
|
||||
char *message_str = python_str_or_unicode_to_string(message);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_chat_show_themed(barejid_str, group_str, key_str, def_str, ch_str, message_str);
|
||||
free(barejid_str);
|
||||
free(group_str);
|
||||
free(key_str);
|
||||
free(def_str);
|
||||
free(ch_str);
|
||||
free(message_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_room_show(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *roomjid = NULL;
|
||||
PyObject *message = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OO", &roomjid, &message)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *roomjid_str = python_str_or_unicode_to_string(roomjid);
|
||||
char *message_str = python_str_or_unicode_to_string(message);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_room_show(roomjid_str, message_str);
|
||||
free(roomjid_str);
|
||||
free(message_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_room_show_themed(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *roomjid = NULL;
|
||||
PyObject *group = NULL;
|
||||
PyObject *key = NULL;
|
||||
PyObject *def = NULL;
|
||||
PyObject *ch = NULL;
|
||||
PyObject *message = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OOOOOO", &roomjid, &group, &key, &def, &ch, &message)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *roomjid_str = python_str_or_unicode_to_string(roomjid);
|
||||
char *group_str = python_str_or_unicode_to_string(group);
|
||||
char *key_str = python_str_or_unicode_to_string(key);
|
||||
char *def_str = python_str_or_unicode_to_string(def);
|
||||
char *ch_str = python_str_or_unicode_to_string(ch);
|
||||
char *message_str = python_str_or_unicode_to_string(message);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_room_show_themed(roomjid_str, group_str, key_str, def_str, ch_str, message_str);
|
||||
free(roomjid_str);
|
||||
free(group_str);
|
||||
free(key_str);
|
||||
free(def_str);
|
||||
free(ch_str);
|
||||
free(message_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@@ -1403,6 +1527,10 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "room_unset_titlebar_enctext", python_api_room_unset_titlebar_enctext, METH_VARARGS, "Reset the encryption status in the title bar for the specified room" },
|
||||
{ "room_set_message_char", python_api_room_set_message_char, METH_VARARGS, "Set the message prefix character for specified room" },
|
||||
{ "room_unset_message_char", python_api_room_unset_message_char, METH_VARARGS, "Reset the message prefix character for specified room" },
|
||||
{ "chat_show", python_api_chat_show, METH_VARARGS, "Print a line in a chat window" },
|
||||
{ "chat_show_themed", python_api_chat_show_themed, METH_VARARGS, "Print a themed line in a chat window" },
|
||||
{ "room_show", python_api_room_show, METH_VARARGS, "Print a line in a chat room window" },
|
||||
{ "room_show_themed", python_api_room_show_themed, METH_VARARGS, "Print a themed line in a chat room window" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user