src/config.c
author Tero Marttila <terom@fixme.fi>
Wed, 27 May 2009 23:07:00 +0300
branchnew-lib-errors
changeset 216 a10ba529ae39
parent 158 b5a5df4f4421
permissions -rw-r--r--
initial error code
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#include "config.h"
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
#include <string.h>
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
     4
#include <assert.h>
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
     6
const struct config_option* config_lookup (const struct config_option *options, const char *name, struct error_info *err)
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
{
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
     8
    const struct config_option *option;
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
    // find the matching config opt
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    11
    for (option = options; option->name; option++) {
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
        if (strcmp(option->name, name) == 0)
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    13
            return option;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    14
    }
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    15
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    16
    // not found
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    17
    SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown configuration option");
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    18
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    19
    return NULL;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    20
}
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    21
122
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    22
int config_params_count (const struct config_option *option)
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    23
{
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    24
    const struct config_param *param;
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    25
    int count = 0;
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    26
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    27
    // handle each param
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    28
    for (param = option->params; param->name && param->type; param++)
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    29
        count++;
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    30
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    31
    return count;
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    32
}
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    33
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    34
/**
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    35
 * Parse a raw value for a CONFIG_IRC_CHAN into an irc_chan
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    36
 */
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    37
static struct irc_chan* config_parse_irc_chan (struct nexus *nexus, char *raw_value, struct error_info *err)
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    38
{
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    39
    const char *network, *channel;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    40
    struct irc_chan *chan;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    41
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    42
    // XXX: wrong error code
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    43
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    44
    // parse required args
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    45
    if ((network = strsep(&raw_value, "/")) == NULL)
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    46
        JUMP_SET_ERROR_STR(err, ERR_CONFIG_VALUE, "invalid <network> for CONFIG_IRC_CHAN value");
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    47
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    48
    if ((channel = strsep(&raw_value, "/")) == NULL)
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    49
        JUMP_SET_ERROR_STR(err, ERR_CONFIG_VALUE, "invalid <channel> for CONFIG_IRC_CHAN value");
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    50
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    51
    // extraneous stuff?
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    52
    if (raw_value)
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    53
        JUMP_SET_ERROR_STR(err, ERR_CONFIG_VALUE, "trailing data for CONFIG_IRC_CHAN value");
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    54
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    55
    // get the channel?
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    56
    if ((chan = irc_client_get_chan(nexus->client, network, channel)) == NULL)
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    57
        JUMP_SET_ERROR_STR(err, ERR_CONFIG_VALUE, "unknown network/channel name for CONFIG_IRC_CHAN value");
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    58
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    59
    // ok
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    60
    return chan;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    61
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    62
error:
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    63
    return NULL;    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    64
}
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    65
122
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    66
err_t config_parse_param (const struct config_param *param, struct nexus *nexus, struct config_value *value, char *raw_value, struct error_info *err)
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    67
{
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    68
    // parse the value 
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    69
    switch (param->type) {
158
b5a5df4f4421 don't assert on CONFIG_INVALID in config_parse_param
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    70
        case CONFIG_INVALID:
b5a5df4f4421 don't assert on CONFIG_INVALID in config_parse_param
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    71
            RETURN_SET_ERROR_STR(err, ERR_CONFIG_TYPE, "invalid value for invalid type (too many values?)");
b5a5df4f4421 don't assert on CONFIG_INVALID in config_parse_param
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    72
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    73
        case CONFIG_STRING:
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    74
            // simple!
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    75
            value->string = raw_value;
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
            break;
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    77
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    78
        case CONFIG_IRC_CHAN:
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    79
            // parse the value
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    80
            if (!(value->irc_chan = config_parse_irc_chan(nexus, raw_value, err)))
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    81
                return ERROR_CODE(err);
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    82
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    83
            break;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    84
        
122
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    85
        case CONFIG_USER:
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    86
            // fail
124
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
    87
            RETURN_SET_ERROR_STR(err, ERR_CONFIG_TYPE, "user type can't be parsed");
122
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
    88
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    89
        default:
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    90
            NOT_REACHED();
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
    }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    93
    // copy the type
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    94
    value->type = param->type;
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    95
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    96
    // ok
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    97
    return SUCCESS; 
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    98
}
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    99
122
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   100
err_t config_parse (const struct config_option *option, struct nexus *nexus, struct config_value *value, char *raw_value, struct error_info *err)
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   101
{
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   102
    // use the first param
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   103
    const struct config_param *param = &option->params[0];
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   104
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   105
    // must have exactly one param
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   106
    if (!param->type || (param + 1)->type)
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   107
        return SET_ERROR(err, ERR_CONFIG_PARAMS);
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   108
    
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   109
    // parse it
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   110
    return config_parse_param(param, nexus, value, raw_value, err);
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   111
}
52ffbdb6bba1 start implementing multiple args for lua_module_conf
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   112
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   113
err_t config_apply_opt (const struct config_option *option, void *ctx, const struct config_value values[], struct error_info *err)
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   114
{
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   115
    const struct config_param *param;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   116
    const struct config_value *value;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   117
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   118
    // handle each param
124
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   119
    for (param = option->params, value = values; param->name && param->type; param++) {
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   120
        // no value given, or value given as NULL?
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   121
        if (!value->type || value->type == CONFIG_NULL) {
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   122
            if (param->optional) {
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   123
                // optional, so just ignore the value 
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   124
                
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   125
            } else {
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   126
                // required
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   127
                JUMP_SET_ERROR_STR(err, ERR_CONFIG_REQUIRED, param->name);
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   128
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   129
            }
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   130
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   131
        } else if (param->type != value->type) {
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   132
            // invalid type, XXX: also report correct type name?
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   133
            JUMP_SET_ERROR(err, ERR_CONFIG_TYPE);
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   134
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   135
        } else if (param->is_handler) {
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   136
            // only applicable for non-optional args
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   137
            err_t tmp;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   138
            
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   139
            // invoke the handler
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   140
            switch (param->type) {
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   141
                case CONFIG_STRING:     tmp = param->func.string(ctx, value->string, err); break;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   142
                case CONFIG_IRC_CHAN:   tmp = param->func.irc_chan(ctx, value->irc_chan, err); break;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   143
                default:                NOT_REACHED();
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   144
            }
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   145
            
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   146
            // abort on errors
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   147
            if (tmp)
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   148
                goto error;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   149
        }
124
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   150
        
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   151
        // the values list is NULL-terminated, and optional params can be left off
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   152
        if (value->type)
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   153
            value++;
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   154
    }
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   155
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   156
    // the option's handler?
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   157
    if (option->func && option->func(ctx, option, values, err))
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   158
        goto error;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   159
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   160
    // ok
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   161
    return SUCCESS;
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   162
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   163
error:
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   164
    return ERROR_CODE(err);
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   165
}
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   166
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   167
err_t config_apply (const struct config_option *options, void *ctx, const char *name, const struct config_value values[], struct error_info *err)
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   168
{
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   169
    const struct config_option *option;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   170
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
    // no matching option found?
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   172
    if (!(option = config_lookup(options, name, err)))
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   173
        return ERROR_CODE(err);
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   174
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   175
    // apply it    
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   176
    return config_apply_opt(option, ctx, values, err);
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   177
}
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   178
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   179
err_t config_apply_string (const struct config_option *options, void *ctx, const char *name, char *value, struct error_info *err)
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   180
{
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   181
    struct config_value conf_value[] = {
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   182
        CONFIG_VALUE_STRING(value),
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   183
        CONFIG_VALUE_END,
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   184
    };
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   185
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   186
    return config_apply(options, ctx, name, conf_value, err);
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
}
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   188
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   189
err_t config_apply_irc_chan (const struct config_option *options, void *ctx, const char *name, struct irc_chan *value, struct error_info *err)
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   190
{
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   191
    struct config_value conf_value[] = {
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   192
        CONFIG_VALUE_IRC_CHAN(value),
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   193
        CONFIG_VALUE_END,
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   194
    };
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   195
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   196
    return config_apply(options, ctx, name, conf_value, err);
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   197
}
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   198
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   199
err_t config_apply_raw (const struct config_option options[], struct nexus *nexus, void *ctx, const char *name, char *raw_value, struct error_info *err)
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   200
{
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   201
    const struct config_option *option;
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   202
    struct config_value value[2] = {
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   203
        CONFIG_VALUE_END,
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   204
        CONFIG_VALUE_END,
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   205
    };
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   206
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   207
    // no matching option found?
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   208
    if (!(option = config_lookup(options, name, err)))
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   209
        return ERROR_CODE(err);
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   210
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   211
    // parse it
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   212
    if (config_parse(option, nexus, &value[0], raw_value, err))
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   213
        return ERROR_CODE(err);
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   214
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   215
    // apply it
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   216
    return config_apply_opt(option, ctx, value, err);
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   217
}
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   218
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   219
const struct config_value* config_get_value (const struct config_option *option, const struct config_value values[], const char *name)
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   220
{
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   221
    const struct config_param *param;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   222
    const struct config_value *value;
124
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   223
    
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
   224
    // go through the (param, value) pairs
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   225
    for (param = option->params, value = values; param->name && param->type && value->type; param++, value++) {
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   226
        if (strcmp(param->name, name) == 0) {
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   227
            // not NULL?
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   228
            if (value->type != CONFIG_NULL)
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   229
                return value;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   230
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   231
            else
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   232
                return NULL;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   233
        }
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   234
    }
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   235
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   236
    // not found
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   237
    return NULL;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   238
}
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   239
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   240
const char* config_get_string (const struct config_option *option, const struct config_value values[], const char *name)
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   241
{
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   242
    const struct config_value *value;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   243
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   244
    return (value = config_get_value(option, values, name)) ? value->string : NULL;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   245
}
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   246
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   247
struct irc_chan* config_get_irc_chan (const struct config_option *option, const struct config_value values[], const char *name)
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   248
{
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   249
    const struct config_value *value;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   250
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   251
    return (value = config_get_value(option, values, name)) ? value->irc_chan : NULL;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   252
}
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   253
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
   254
void* config_get_user (const struct config_option *option, const struct config_value values[], const char *name, const struct config_user_type *user_type)
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   255
{
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   256
    const struct config_value *value;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   257
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
   258
    return ((value = config_get_value(option, values, name)) && value->user.type == user_type) ? value->user.ptr : NULL;
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   259
}
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   260