1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
|
/*
* api.c
* vim: expandtab:ts=4:sts=4:sw=4
*
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
#include "profanity.h"
#include "log.h"
#include "common.h"
#include "config/theme.h"
#include "command/cmd_defs.h"
#include "event/server_events.h"
#include "event/client_events.h"
#include "plugins/callbacks.h"
#include "plugins/autocompleters.h"
#include "plugins/themes.h"
#include "plugins/settings.h"
#include "plugins/disco.h"
#include "ui/ui.h"
#include "ui/window_list.h"
void
api_cons_alert(void)
{
cons_alert(NULL);
}
int
api_cons_show(const char* const message)
{
if (message == NULL) {
log_warning("%s", "prof_cons_show failed, message is NULL");
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
cons_show("%s", parsed);
free(parsed);
return 1;
}
int
api_cons_show_themed(const char* const group, const char* const key, const char* const def, const char* const message)
{
if (message == NULL) {
log_warning("%s", "prof_cons_show_themed failed, message is NULL");
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
theme_item_t themeitem = plugin_themes_get(group, key, def);
ProfWin* console = wins_get_console();
win_println(console, themeitem, "-", "%s", parsed);
free(parsed);
return 1;
}
int
api_cons_bad_cmd_usage(const char* const cmd)
{
if (cmd == NULL) {
log_warning("%s", "prof_cons_bad_cmd_usage failed, cmd is NULL");
return 0;
}
cons_bad_cmd_usage(cmd);
return 1;
}
void
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))
{
PluginCommand* command = malloc(sizeof(PluginCommand));
command->command_name = strdup(command_name);
command->min_args = min_args;
command->max_args = max_args;
command->callback = callback;
command->callback_exec = callback_exec;
command->callback_destroy = callback_destroy;
CommandHelp* help = malloc(sizeof(CommandHelp));
help->tags[0] = NULL;
int i;
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;
callbacks_add_command(plugin_name, command);
}
void
api_register_timed(const char* const plugin_name, void* callback, int interval_seconds,
void (*callback_exec)(PluginTimedFunction* timed_function), void (*callback_destroy)(void* callback))
{
PluginTimedFunction* timed_function = malloc(sizeof(PluginTimedFunction));
timed_function->callback = callback;
timed_function->callback_exec = callback_exec;
timed_function->callback_destroy = callback_destroy;
timed_function->interval_seconds = interval_seconds;
timed_function->timer = g_timer_new();
callbacks_add_timed(plugin_name, timed_function);
}
void
api_completer_add(const char* const plugin_name, const char* key, char** items)
{
autocompleters_add(plugin_name, key, items);
}
void
api_completer_remove(const char* const plugin_name, const char* key, char** items)
{
autocompleters_remove(plugin_name, key, items);
}
void
api_completer_clear(const char* const plugin_name, const char* key)
{
autocompleters_clear(plugin_name, key);
}
void
api_filepath_completer_add(const char* const plugin_name, const char* prefix)
{
autocompleters_filepath_add(plugin_name, prefix);
}
void
api_notify(const char* message, const char* category, int timeout_ms)
{
notify(message, timeout_ms, category);
}
void
api_send_line(char* line)
{
ProfWin* current = wins_get_current();
cmd_process_input(current, line);
}
char*
api_get_current_recipient(void)
{
ProfWin* current = wins_get_current();
if (current->type == WIN_CHAT) {
ProfChatWin* chatwin = (ProfChatWin*)current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
return chatwin->barejid;
} else {
return NULL;
}
}
char*
api_get_current_muc(void)
{
ProfWin* current = wins_get_current();
if (current->type == WIN_MUC) {
ProfMucWin* mucwin = (ProfMucWin*)current;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return mucwin->roomjid;
} else {
return NULL;
}
}
char*
api_get_current_nick(void)
{
ProfWin* current = wins_get_current();
if (current->type == WIN_MUC) {
ProfMucWin* mucwin = (ProfMucWin*)current;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return muc_nick(mucwin->roomjid);
} else {
return NULL;
}
}
char**
api_get_current_occupants(void)
{
ProfWin* current = wins_get_current();
if (current->type == WIN_MUC) {
ProfMucWin* mucwin = (ProfMucWin*)current;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
GList* occupants_list = muc_roster(mucwin->roomjid);
char** result = malloc((g_list_length(occupants_list) + 1) * sizeof(char*));
GList* curr = occupants_list;
int i = 0;
while (curr) {
Occupant* occupant = curr->data;
result[i++] = strdup(occupant->nick);
curr = g_list_next(curr);
}
result[i] = NULL;
return result;
} else {
return NULL;
}
}
int
api_current_win_is_console(void)
{
ProfWin* current = wins_get_current();
if (current && current->type == WIN_CONSOLE) {
return 1;
} else {
return 0;
}
}
char*
api_get_room_nick(const char* barejid)
{
return muc_nick(barejid);
}
void
api_log_debug(const char* message)
{
log_debug("%s", message);
}
void
api_log_info(const char* message)
{
log_info("%s", message);
}
void
api_log_warning(const char* message)
{
log_warning("%s", message);
}
void
api_log_error(const char* message)
{
log_error("%s", message);
}
int
api_win_exists(const char* tag)
{
return (wins_get_plugin(tag) != NULL);
}
void
api_win_create(
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))
{
if (callbacks_win_exists(plugin_name, tag)) {
if (callback_destroy) {
callback_destroy(callback);
}
return;
}
PluginWindowCallback* window = malloc(sizeof(PluginWindowCallback));
window->callback = callback;
window->callback_exec = callback_exec;
window->callback_destroy = callback_destroy;
callbacks_add_window_handler(plugin_name, tag, window);
wins_new_plugin(plugin_name, tag);
// set status bar active
ProfPluginWin* pluginwin = wins_get_plugin(tag);
int num = wins_get_num((ProfWin*)pluginwin);
status_bar_active(num, WIN_PLUGIN, pluginwin->tag);
}
int
api_win_focus(const char* tag)
{
if (tag == NULL) {
log_warning("%s", "prof_win_focus failed, tag is NULL");
return 0;
}
ProfPluginWin* pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_focus failed, no window with tag: %s", tag);
return 0;
}
ui_focus_win((ProfWin*)pluginwin);
return 1;
}
int
api_win_show(const char* tag, const char* line)
{
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;
}
ProfPluginWin* pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show failed, no window with tag: %s", tag);
return 0;
}
ProfWin* window = (ProfWin*)pluginwin;
win_println(window, THEME_DEFAULT, "!", "%s", line);
return 1;
}
int
api_win_show_themed(const char* tag, const char* const group, const char* const key, const char* const def, const char* line)
{
if (tag == NULL) {
log_warning("%s", "prof_win_show_themed failed, tag is NULL");
return 0;
}
if (line == NULL) {
log_warning("%s", "prof_win_show_themed failed, line is NULL");
return 0;
}
ProfPluginWin* pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show_themed failed, no window with tag: %s", tag);
return 0;
}
theme_item_t themeitem = plugin_themes_get(group, key, def);
ProfWin* window = (ProfWin*)pluginwin;
win_println(window, themeitem, "!", "%s", line);
return 1;
}
int
api_send_stanza(const char* const stanza)
{
return connection_send_stanza(stanza);
}
gboolean
api_settings_boolean_get(const char* const group, const char* const key, gboolean def)
{
return plugin_settings_boolean_get(group, key, def);
}
void
api_settings_boolean_set(const char* const group, const char* const key, gboolean value)
{
plugin_settings_boolean_set(group, key, value);
}
char*
api_settings_string_get(const char* const group, const char* const key, const char* const def)
{
return plugin_settings_string_get(group, key, def);
}
void
api_settings_string_set(const char* const group, const char* const key, const char* const value)
{
plugin_settings_string_set(group, key, value);
}
char**
api_settings_string_list_get(const char* const group, const char* const key)
{
return plugin_settings_string_list_get(group, key);
}
void
api_settings_string_list_add(const char* const group, const char* const key, const char* const value)
{
plugin_settings_string_list_add(group, key, value);
}
int
api_settings_string_list_remove(const char* const group, const char* const key, const char* const value)
{
return plugin_settings_string_list_remove(group, key, value);
}
int
api_settings_string_list_clear(const char* const group, const char* const key)
{
return plugin_settings_string_list_clear(group, key);
}
int
api_settings_int_get(const char* const group, const char* const key, int def)
{
return plugin_settings_int_get(group, key, def);
}
void
api_settings_int_set(const char* const group, const char* const key, int value)
{
plugin_settings_int_set(group, key, value);
}
void
api_incoming_message(const char* const barejid, const char* const resource, const char* const plain)
{
ProfMessage* message = message_init();
message->from_jid = jid_create_from_bare_and_resource(barejid, resource);
message->plain = strdup(plain);
sv_ev_incoming_message(message);
// TODO handle all states
sv_ev_activity((char*)barejid, (char*)resource, FALSE);
message_free(message);
}
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;
}
disco_add_feature(plugin_name, feature);
caps_reset_ver();
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, 0);
}
}
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;
}
#ifdef HAVE_LIBGPGME
if (chatwin->pgp_send) {
chatwin->pgp_send = FALSE;
win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "PGP encryption disabled.");
}
#endif
#ifdef HAVE_LIBOTR
if (chatwin->is_otr) {
chatwin_otr_unsecured(chatwin);
otr_end_session(chatwin->barejid);
}
#endif
}
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;
}
chatwin_set_enctext(chatwin, enctext);
return 1;
}
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;
}
chatwin_unset_enctext(chatwin);
return 1;
}
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;
}
chatwin_set_incoming_char(chatwin, ch);
return 1;
}
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;
}
chatwin_unset_incoming_char(chatwin);
return 1;
}
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;
}
chatwin_set_outgoing_char(chatwin, ch);
return 1;
}
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;
}
chatwin_unset_outgoing_char(chatwin);
return 1;
}
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, could not find room window for %s", roomjid);
return 0;
}
mucwin_set_enctext(mucwin, enctext);
return 1;
}
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, could not find room window for %s", roomjid);
return 0;
}
mucwin_unset_enctext(mucwin);
return 1;
}
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;
}
mucwin_set_message_char(mucwin, ch);
return 1;
}
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;
}
mucwin_unset_message_char(mucwin);
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 (g_utf8_strlen(ch, 4) != 1) {
log_warning("%s", "api_chat_show_themed failed, ch must be a string of length 1");
return 0;
} else {
show_ch = (char*)ch;
}
}
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 (g_utf8_strlen(ch, 4) != 1) {
log_warning("%s", "api_room_show_themed failed, ch must be a string of length 1");
return 0;
} else {
show_ch = (char*)ch;
}
}
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;
}
|