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
|
/*
* trigger-config.c - trigger configuration options (file trigger.conf)
*
* Copyright (C) 2014-2023 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat 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.
*
* WeeChat 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 WeeChat. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "trigger.h"
#include "trigger-config.h"
struct t_config_file *trigger_config_file = NULL;
struct t_config_section *trigger_config_section_trigger = NULL;
/* trigger config, look section */
struct t_config_option *trigger_config_look_enabled;
struct t_config_option *trigger_config_look_monitor_strip_colors;
/* trigger config, color section */
struct t_config_option *trigger_config_color_flag_command;
struct t_config_option *trigger_config_color_flag_conditions;
struct t_config_option *trigger_config_color_flag_regex;
struct t_config_option *trigger_config_color_flag_return_code;
struct t_config_option *trigger_config_color_flag_post_action;
struct t_config_option *trigger_config_color_identifier;
struct t_config_option *trigger_config_color_regex;
struct t_config_option *trigger_config_color_replace;
struct t_config_option *trigger_config_color_trigger;
struct t_config_option *trigger_config_color_trigger_disabled;
char *trigger_config_default_list[][1 + TRIGGER_NUM_OPTIONS] =
{
/*
* beep on highlight/private message, on following conditions:
* - message is displayed (not filtered)
* AND:
* - message does not have tag "notify_none"
* AND:
* - message is a highlight
* OR:
* - message is a message in a private buffer
* AND:
* - buffer notify is NOT "none"
*/
{ "beep", "on",
"print",
"",
"${tg_displayed} "
"&& ${tg_tags} !!- ,notify_none, "
"&& (${tg_highlight} || ${tg_msg_pv}) "
"&& ${buffer.notify} > 0",
"",
"/print -beep",
"ok",
"" },
/*
* hide passwords in commands:
* - /msg [-server <name>] nickserv id <password>
* - /msg [-server <name>] nickserv identify <password>
* - /msg [-server <name>] nickserv ghost <nick> <password>
* - /msg [-server <name>] nickserv release <nick> <password>
* - /msg [-server <name>] nickserv regain <nick> <password>
* - /msg [-server <name>] nickserv recover <nick> <password>
* - /msg [-server <name>] nickserv setpass <nick> <key> <password>
* - /oper <nick> <password>
* - /quote pass <password>
* - /secure passphrase <passphrase>
* - /secure decrypt <passphrase>
* - /secure set <name> <value>
*/
{ "cmd_pass", "on",
"modifier",
"5000|input_text_display;5000|history_add;5000|irc_command_auth",
"",
"s==^("
"(/(msg|m|quote) +(-server +[^ ]+ +)?nickserv +("
"id|"
"identify|"
"set +password|"
"ghost +[^ ]+|"
"release +[^ ]+|"
"regain +[^ ]+|"
"recover +[^ ]+|"
"setpass +[^ ]+"
") +)|"
"/oper +[^ ]+ +|"
"/quote +pass +|"
"/secure +(passphrase|decrypt|set +[^ ]+) +"
")"
"(.*)"
"==${re:1}${hide:*,${re:+}}",
"",
"",
"" },
/*
* hide passwords in commands:
* - /msg [-server <name>] nickserv register <password> <email>
*/
{ "cmd_pass_register", "on",
"modifier",
"5000|input_text_display;5000|history_add;5000|irc_command_auth",
"",
"s==^(/(msg|m|quote) +(-server +[^ ]+ +)?nickserv +register +)([^ ]+)(.*)"
"==${re:1}${hide:*,${re:4}}${re:5}",
"",
"",
"" },
/*
* hide password in IRC auth message displayed (message received from
* server after the user issued the command):
* - id <password>
* - identify <password>
* - set password <password>
* - register <password>
* - ghost <nick> <password>
* - release <nick> <password>
* - regain <nick> <password>
* - recover <nick> <password>
*/
{ "msg_auth", "on",
"modifier",
"5000|irc_message_auth",
"",
"s==^(.*("
"id|"
"identify|"
"set +password|"
"register|"
"ghost +[^ ]+|"
"release +[^ ]+|"
"regain +[^ ]+|"
"recover +[^ ]+"
") +)(.*)"
"==${re:1}${hide:*,${re:+}}",
"",
"",
"" },
/*
* hide server password in commands:
* - /server add <name> <address> -password=<password>
* - /server add <name> <address> -sasl_password=<password>
* - /connect <address> -password=<password>
* - /connect <address> -sasl_password=<password>
*/
{ "server_pass", "on",
"modifier",
"5000|input_text_display;5000|history_add",
"",
"s==^(/(server|connect) .*-(sasl_)?password=)([^ ]+)(.*)"
"==${re:1}${hide:*,${re:4}}${re:5}"
"",
"",
"" },
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
};
/*
* Callback for changes on option "trigger.look.enabled".
*/
void
trigger_config_change_enabled (const void *pointer, void *data,
struct t_config_option *option)
{
/* make C compiler happy */
(void) pointer;
(void) data;
trigger_enabled = weechat_config_boolean (option);
}
/*
* Callback for changes on option "trigger.trigger.xxx.enabled".
*/
void
trigger_config_change_trigger_enabled (const void *pointer, void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
/* make C compiler happy */
(void) pointer;
(void) data;
ptr_trigger = trigger_search_with_option (option);
if (!ptr_trigger)
return;
if (weechat_config_boolean (option))
trigger_hook (ptr_trigger);
else
trigger_unhook (ptr_trigger);
}
/*
* Callback for changes on option "trigger.trigger.xxx.hook".
*/
void
trigger_config_change_trigger_hook (const void *pointer, void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
/* make C compiler happy */
(void) pointer;
(void) data;
ptr_trigger = trigger_search_with_option (option);
if (!ptr_trigger)
return;
if (ptr_trigger->options[TRIGGER_OPTION_ARGUMENTS])
trigger_hook (ptr_trigger);
}
/*
* Callback for changes on option "trigger.trigger.xxx.arguments".
*/
void
trigger_config_change_trigger_arguments (const void *pointer, void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
/* make C compiler happy */
(void) pointer;
(void) data;
ptr_trigger = trigger_search_with_option (option);
if (!ptr_trigger)
return;
if (ptr_trigger->options[TRIGGER_OPTION_HOOK])
trigger_hook (ptr_trigger);
}
/*
* Callback for changes on option "trigger.trigger.xxx.regex".
*/
void
trigger_config_change_trigger_regex (const void *pointer, void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
/* make C compiler happy */
(void) pointer;
(void) data;
ptr_trigger = trigger_search_with_option (option);
if (!ptr_trigger)
return;
switch (trigger_regex_split (weechat_config_string (option),
&ptr_trigger->regex_count,
&ptr_trigger->regex))
{
case 0: /* OK */
break;
case -1: /* format error */
weechat_printf (NULL,
_("%s%s: invalid format for option \"regex\", "
"see /help trigger.trigger.%s.regex"),
weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
ptr_trigger->name);
break;
case -2: /* regex compilation error */
weechat_printf (NULL,
_("%s%s: invalid regular expression in option "
"\"regex\", see /help trigger.trigger.%s.regex"),
weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
ptr_trigger->name);
break;
case -3: /* memory error */
weechat_printf (NULL,
_("%s%s: not enough memory"),
weechat_prefix ("error"), TRIGGER_PLUGIN_NAME);
break;
}
}
/*
* Callback for changes on option "trigger.trigger.xxx.command".
*/
void
trigger_config_change_trigger_command (const void *pointer, void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
/* make C compiler happy */
(void) pointer;
(void) data;
ptr_trigger = trigger_search_with_option (option);
if (!ptr_trigger)
return;
trigger_split_command (weechat_config_string (option),
&ptr_trigger->commands_count,
&ptr_trigger->commands);
}
/*
* Creates an option for a trigger.
*
* Returns pointer to new option, NULL if error.
*/
struct t_config_option *
trigger_config_create_trigger_option (const char *trigger_name, int index_option,
const char *value)
{
struct t_config_option *ptr_option;
int length;
char *option_name;
ptr_option = NULL;
length = strlen (trigger_name) + 1 +
strlen (trigger_option_string[index_option]) + 1;
option_name = malloc (length);
if (!option_name)
return NULL;
snprintf (option_name, length, "%s.%s",
trigger_name, trigger_option_string[index_option]);
switch (index_option)
{
case TRIGGER_OPTION_ENABLED:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "boolean",
N_("if disabled, the hooks are removed from trigger, so it is "
"not called any more"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, NULL,
&trigger_config_change_trigger_enabled, NULL, NULL,
NULL, NULL, NULL);
break;
case TRIGGER_OPTION_HOOK:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "integer",
N_("type of hook used"),
trigger_hook_option_values,
0, 0, value, NULL, 0,
NULL, NULL, NULL,
&trigger_config_change_trigger_hook, NULL, NULL,
NULL, NULL, NULL);
break;
case TRIGGER_OPTION_ARGUMENTS:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "string",
N_("arguments for the hook (depend on the hook type, see /help "
"trigger)"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, NULL,
&trigger_config_change_trigger_arguments, NULL, NULL,
NULL, NULL, NULL);
break;
case TRIGGER_OPTION_CONDITIONS:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "string",
N_("condition(s) for running the command (it is checked in "
"hook callback) (note: content is evaluated when trigger is "
"run, see /help eval)"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_REGEX:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "string",
N_("replace text with a POSIX extended regular expression (it "
"is done only if conditions are OK, and before running the "
"command) (note: content is evaluated when trigger is run, "
"see /help eval); format is: \"/regex/replace/var\" (var "
"is the hashtable variable to replace, it is optional), "
"many regex can be separated by a space, for example: "
"\"/regex1/replace1/var1 /regex2/replace2/var2\"; escaped "
"chars are interpreted in the regex (for example \"\\n\"); "
"the separator \"/\" can be replaced by any char (one or "
"more identical chars); matching groups can be used in "
"replace: ${re:0} to ${re:99}, ${re:+} for last match and "
"${hide:c,${re:N}} to replace all chars of group N by "
"char 'c'"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, NULL,
&trigger_config_change_trigger_regex, NULL, NULL,
NULL, NULL, NULL);
break;
case TRIGGER_OPTION_COMMAND:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "string",
N_("command(s) to run if conditions are OK, after regex "
"replacements (many commands can be separated by semicolons)"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, NULL,
&trigger_config_change_trigger_command, NULL, NULL,
NULL, NULL, NULL);
break;
case TRIGGER_OPTION_RETURN_CODE:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "integer",
N_("return code for hook callback (see plugin API reference to "
"know where ok_eat/error can be used efficiently)"),
"ok|ok_eat|error", 0, 0, value, NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_POST_ACTION:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "integer",
N_("action to take on the trigger after execution"),
"none|disable|delete", 0, 0, value, NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
break;
case TRIGGER_NUM_OPTIONS:
break;
}
free (option_name);
return ptr_option;
}
/*
* Creates option for a temporary trigger (when reading configuration file).
*/
void
trigger_config_create_option_temp (struct t_trigger *temp_trigger,
int index_option, const char *value)
{
struct t_config_option *new_option;
new_option = trigger_config_create_trigger_option (temp_trigger->name,
index_option, value);
if (new_option
&& (index_option >= 0) && (index_option < TRIGGER_NUM_OPTIONS))
{
temp_trigger->options[index_option] = new_option;
}
}
/*
* Uses temporary triggers (created by reading configuration file).
*/
void
trigger_config_use_temp_triggers ()
{
struct t_trigger *ptr_temp_trigger, *next_temp_trigger;
int i, num_options_ok;
for (ptr_temp_trigger = triggers_temp; ptr_temp_trigger;
ptr_temp_trigger = ptr_temp_trigger->next_trigger)
{
num_options_ok = 0;
for (i = 0; i < TRIGGER_NUM_OPTIONS; i++)
{
if (!ptr_temp_trigger->options[i])
{
ptr_temp_trigger->options[i] =
trigger_config_create_trigger_option (ptr_temp_trigger->name,
i,
trigger_option_default[i]);
}
if (ptr_temp_trigger->options[i])
num_options_ok++;
}
if (num_options_ok == TRIGGER_NUM_OPTIONS)
{
trigger_new_with_options (ptr_temp_trigger->name,
ptr_temp_trigger->options);
}
else
{
for (i = 0; i < TRIGGER_NUM_OPTIONS; i++)
{
if (ptr_temp_trigger->options[i])
{
weechat_config_option_free (ptr_temp_trigger->options[i]);
ptr_temp_trigger->options[i] = NULL;
}
}
}
}
/* free all temporary triggers */
while (triggers_temp)
{
next_temp_trigger = triggers_temp->next_trigger;
if (triggers_temp->name)
free (triggers_temp->name);
free (triggers_temp);
triggers_temp = next_temp_trigger;
}
last_trigger_temp = NULL;
}
/*
* Reads a trigger option in trigger configuration file.
*/
int
trigger_config_trigger_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name, const char *value)
{
char *pos_option, *trigger_name;
struct t_trigger *ptr_temp_trigger;
int index_option;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) config_file;
(void) section;
if (!option_name)
return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
pos_option = strchr (option_name, '.');
if (!pos_option)
return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
trigger_name = weechat_strndup (option_name, pos_option - option_name);
if (!trigger_name)
return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
pos_option++;
/* search temporary trigger */
for (ptr_temp_trigger = triggers_temp; ptr_temp_trigger;
ptr_temp_trigger = ptr_temp_trigger->next_trigger)
{
if (strcmp (ptr_temp_trigger->name, trigger_name) == 0)
break;
}
if (!ptr_temp_trigger)
{
/* create new temporary trigger */
ptr_temp_trigger = trigger_alloc (trigger_name);
if (ptr_temp_trigger)
trigger_add (ptr_temp_trigger, &triggers_temp, &last_trigger_temp);
}
if (ptr_temp_trigger)
{
index_option = trigger_search_option (pos_option);
if (index_option >= 0)
{
trigger_config_create_option_temp (ptr_temp_trigger, index_option,
value);
}
else
{
weechat_printf (NULL,
_("%sWarning: unknown option for section \"%s\": "
"%s (value: \"%s\")"),
weechat_prefix ("error"),
TRIGGER_CONFIG_SECTION_TRIGGER,
option_name, value);
}
}
free (trigger_name);
return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
}
/*
* Writes default triggers in trigger configuration file.
*/
int
trigger_config_trigger_write_default_cb (const void *pointer, void *data,
struct t_config_file *config_file,
const char *section_name)
{
int i, j, quotes;
char option_name[512];
/* make C compiler happy */
(void) pointer;
(void) data;
if (!weechat_config_write_line (config_file, section_name, NULL))
return WEECHAT_CONFIG_WRITE_ERROR;
for (i = 0; trigger_config_default_list[i][0]; i++)
{
for (j = 0; j < TRIGGER_NUM_OPTIONS; j++)
{
snprintf (option_name, sizeof (option_name),
"%s.%s",
trigger_config_default_list[i][0],
trigger_option_string[j]);
quotes = (j & (TRIGGER_OPTION_ARGUMENTS | TRIGGER_OPTION_CONDITIONS |
TRIGGER_OPTION_REGEX | TRIGGER_OPTION_COMMAND));
if (!weechat_config_write_line (config_file, option_name, "%s%s%s",
(quotes) ? "\"" : "",
trigger_config_default_list[i][j + 1],
(quotes) ? "\"" : ""))
{
return WEECHAT_CONFIG_WRITE_ERROR;
}
}
}
return WEECHAT_CONFIG_WRITE_OK;
}
/*
* Reloads trigger configuration file.
*/
int
trigger_config_reload_cb (const void *pointer, void *data,
struct t_config_file *config_file)
{
int rc;
/* make C compiler happy */
(void) pointer;
(void) data;
trigger_free_all ();
rc = weechat_config_reload (config_file);
trigger_config_use_temp_triggers ();
return rc;
}
/*
* Initializes trigger configuration file.
*
* Returns:
* 1: OK
* 0: error
*/
int
trigger_config_init ()
{
struct t_config_section *ptr_section;
trigger_config_file = weechat_config_new (
TRIGGER_CONFIG_NAME, &trigger_config_reload_cb, NULL, NULL);
if (!trigger_config_file)
return 0;
/* look */
ptr_section = weechat_config_new_section (trigger_config_file, "look",
0, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
if (!ptr_section)
{
weechat_config_free (trigger_config_file);
trigger_config_file = NULL;
return 0;
}
trigger_config_look_enabled = weechat_config_new_option (
trigger_config_file, ptr_section,
"enabled", "boolean",
N_("enable trigger support"),
NULL, 0, 0, "on", NULL, 0,
NULL, NULL, NULL,
&trigger_config_change_enabled, NULL, NULL,
NULL, NULL, NULL);
trigger_config_look_monitor_strip_colors = weechat_config_new_option (
trigger_config_file, ptr_section,
"monitor_strip_colors", "boolean",
N_("strip colors in hashtable values displayed on monitor buffer"),
NULL, 0, 0, "off", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
/* color */
ptr_section = weechat_config_new_section (trigger_config_file, "color",
0, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
if (!ptr_section)
{
weechat_config_free (trigger_config_file);
trigger_config_file = NULL;
return 0;
}
trigger_config_color_flag_command = weechat_config_new_option (
trigger_config_file, ptr_section,
"flag_command", "color",
N_("text color for command flag (in /trigger list)"),
NULL, 0, 0, "lightgreen", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_flag_conditions = weechat_config_new_option (
trigger_config_file, ptr_section,
"flag_conditions", "color",
N_("text color for conditions flag (in /trigger list)"),
NULL, 0, 0, "yellow", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_flag_regex = weechat_config_new_option (
trigger_config_file, ptr_section,
"flag_regex", "color",
N_("text color for regex flag (in /trigger list)"),
NULL, 0, 0, "lightcyan", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_flag_return_code = weechat_config_new_option (
trigger_config_file, ptr_section,
"flag_return_code", "color",
N_("text color for return code flag (in /trigger list)"),
NULL, 0, 0, "lightmagenta", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_flag_post_action = weechat_config_new_option (
trigger_config_file, ptr_section,
"flag_post_action", "color",
N_("text color for post action flag (in /trigger list)"),
NULL, 0, 0, "lightblue", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_identifier = weechat_config_new_option (
trigger_config_file, ptr_section,
"identifier", "color",
N_("text color for trigger context identifier in monitor buffer"),
NULL, 0, 0, "cyan", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_regex = weechat_config_new_option (
trigger_config_file, ptr_section,
"regex", "color",
N_("text color for regular expressions"),
NULL, 0, 0, "white", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_replace = weechat_config_new_option (
trigger_config_file, ptr_section,
"replace", "color",
N_("text color for replacement text (for regular expressions)"),
NULL, 0, 0, "cyan", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_trigger = weechat_config_new_option (
trigger_config_file, ptr_section,
"trigger", "color",
N_("text color for trigger name"),
NULL, 0, 0, "green", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
trigger_config_color_trigger_disabled = weechat_config_new_option (
trigger_config_file, ptr_section,
"trigger_disabled", "color",
N_("text color for disabled trigger name"),
NULL, 0, 0, "red", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
/* trigger */
ptr_section = weechat_config_new_section (
trigger_config_file,
TRIGGER_CONFIG_SECTION_TRIGGER,
0, 0,
&trigger_config_trigger_read_cb, NULL, NULL,
NULL, NULL, NULL,
&trigger_config_trigger_write_default_cb, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
if (!ptr_section)
{
weechat_config_free (trigger_config_file);
trigger_config_file = NULL;
return 0;
}
trigger_config_section_trigger = ptr_section;
return 1;
}
/*
* Reads trigger configuration file.
*/
int
trigger_config_read ()
{
int rc;
rc = weechat_config_read (trigger_config_file);
trigger_config_use_temp_triggers ();
return rc;
}
/*
* Writes trigger configuration file.
*/
int
trigger_config_write ()
{
return weechat_config_write (trigger_config_file);
}
/*
* Frees trigger configuration.
*/
void
trigger_config_free ()
{
weechat_config_free (trigger_config_file);
}
|