summaryrefslogtreecommitdiff
path: root/src/plugins/fifo/fifo-config.c
blob: 09058c58b49d29775d1b20d3ea3a2f61dea7af02 (plain)
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
/*
 * fifo-config.c - fifo configuration options (file fifo.conf)
 *
 * Copyright (C) 2003-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 "../weechat-plugin.h"
#include "fifo.h"
#include "fifo-config.h"


struct t_config_file *fifo_config_file = NULL;

/* sections */

struct t_config_section *fifo_config_section_file = NULL;

/* fifo config, file section */

struct t_config_option *fifo_config_file_enabled = NULL;
struct t_config_option *fifo_config_file_path = NULL;


/*
 * Callback for changes on option "enabled".
 */

void
fifo_config_change_file_enabled (const void *pointer, void *data,
                                 struct t_config_option *option)
{
    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) option;

    fifo_remove ();

    if (weechat_config_boolean (fifo_config_file_enabled))
        fifo_create ();
}

/*
 * Callback for changes on option "path".
 */

void
fifo_config_change_file_path (const void *pointer, void *data,
                              struct t_config_option *option)
{
    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) option;

    fifo_quiet = 1;

    fifo_remove ();
    fifo_create ();

    fifo_quiet = 0;
}

/*
 * Initializes fifo configuration file.
 *
 * Returns:
 *   1: OK
 *   0: error
 */

int
fifo_config_init ()
{
    fifo_config_file = weechat_config_new (FIFO_CONFIG_PRIO_NAME,
                                           NULL, NULL, NULL);
    if (!fifo_config_file)
        return 0;

    /* file */
    fifo_config_section_file = weechat_config_new_section (
        fifo_config_file, "file",
        0, 0,
        NULL, NULL, NULL,
        NULL, NULL, NULL,
        NULL, NULL, NULL,
        NULL, NULL, NULL,
        NULL, NULL, NULL);
    if (fifo_config_section_file)
    {
        fifo_config_file_enabled = weechat_config_new_option (
            fifo_config_file, fifo_config_section_file,
            "enabled", "boolean",
            N_("enable FIFO pipe"),
            NULL, 0, 0, "on", NULL, 0,
            NULL, NULL, NULL,
            &fifo_config_change_file_enabled, NULL, NULL,
            NULL, NULL, NULL);
        fifo_config_file_path = weechat_config_new_option (
            fifo_config_file, fifo_config_section_file,
            "path", "string",
            N_("path for FIFO file; "
               "WeeChat PID can be used in path with ${info:pid} "
               "(path is evaluated, see function string_eval_path_home in "
               "plugin API reference)"),
            NULL, 0, 0, "${weechat_runtime_dir}/weechat_fifo_${info:pid}", NULL, 0,
            NULL, NULL, NULL,
            fifo_config_change_file_path, NULL, NULL,
            NULL, NULL, NULL);
    }

    return 1;
}

/*
 * Reads fifo configuration file.
 */

int
fifo_config_read ()
{
    return weechat_config_read (fifo_config_file);
}

/*
 * Writes fifo configuration file.
 */

int
fifo_config_write ()
{
    return weechat_config_write (fifo_config_file);
}

/*
 * Frees fifo configuration.
 */

void
fifo_config_free ()
{
    weechat_config_free (fifo_config_file);
    fifo_config_file = NULL;
}