diff options
35 files changed, 526 insertions, 186 deletions
diff --git a/src/core/commands.h b/src/core/commands.h index 0b599f54..bdc8755d 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -37,7 +37,8 @@ enum { CMDERR_CHAN_NOT_FOUND, /* channel not found */ CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */ CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */ - CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */ + CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */ + CMDERR_INVALID_TIME /* invalid time specification */ }; /* Return the full command for `alias' */ diff --git a/src/core/log-away.c b/src/core/log-away.c index 724e4b4a..586d17d4 100644 --- a/src/core/log-away.c +++ b/src/core/log-away.c @@ -38,16 +38,13 @@ static void sig_log_written(LOG_REC *log) static void awaylog_open(void) { - const char *fname, *levelstr; + const char *fname; LOG_REC *log; int level; fname = settings_get_str("awaylog_file"); - levelstr = settings_get_str("awaylog_level"); - if (*fname == '\0' || *levelstr == '\0') return; - - level = level2bits(levelstr); - if (level == 0) return; + level = settings_get_level("awaylog_level"); + if (*fname == '\0' || level == 0) return; log = log_find(fname); if (log != NULL && log->handle != -1) @@ -106,7 +103,7 @@ void log_away_init(void) away_msgs = 0; settings_add_str("log", "awaylog_file", IRSSI_DIR_SHORT"/away.log"); - settings_add_str("log", "awaylog_level", "msgs hilight"); + settings_add_level("log", "awaylog_level", "msgs hilight"); signal_add("log written", (SIGNAL_FUNC) sig_log_written); signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed); diff --git a/src/core/misc.c b/src/core/misc.c index 89f564d3..46720d62 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -816,3 +816,117 @@ int nearest_power(int num) while (n < num) n <<= 1; return n; } + +int parse_time_interval(const char *time, int *msecs) +{ + const char *desc; + int number, len; + + *msecs = 0; + + /* max. return value is about 1.6 years */ + number = 0; + for (;;) { + if (i_isdigit(*time)) { + number = number*10 + (*time - '0'); + time++; + continue; + } + + /* skip punctuation */ + while (*time != '\0' && i_ispunct(*time)) + time++; + + /* get description */ + for (len = 0, desc = time; i_isalpha(*time); time++) + len++; + + if (len == 0) { + if (number == 0) { + /* "0" - allow it */ + return TRUE; + } + + *msecs += number; /* assume seconds */ + return FALSE; + } + + if (g_strncasecmp(desc, "weeks", len) == 0) + *msecs += number * 1000*3600*7; + if (g_strncasecmp(desc, "days", len) == 0) + *msecs += number * 1000*3600; + else if (g_strncasecmp(desc, "minutes", len) == 0 || + g_strncasecmp(desc, "mins", len) == 0) + *msecs += number * 1000*60; + else if (g_strncasecmp(desc, "seconds", len) == 0 || + g_strncasecmp(desc, "secs", len) == 0) + *msecs += number * 1000; + else if (g_strncasecmp(desc, "milliseconds", len) == 0 || + g_strncasecmp(desc, "millisecs", len) == 0 || + g_strncasecmp(desc, "mseconds", len) == 0 || + g_strncasecmp(desc, "msecs", len) == 0) + *msecs += number; + + /* skip punctuation */ + while (*time != '\0' && i_ispunct(*time)) + time++; + + if (*time == '\0') + break; + + number = 0; + } + + return TRUE; +} + +int parse_size(const char *size, int *bytes) +{ + const char *desc; + int number, len; + + *bytes = 0; + + /* max. return value is about 1.6 years */ + number = 0; + while (*size != '\0') { + if (i_isdigit(*size)) { + number = number*10 + (*size - '0'); + size++; + continue; + } + + /* skip punctuation */ + while (*size != '\0' && i_ispunct(*size)) + size++; + + /* get description */ + for (len = 0, desc = size; i_isalpha(*size); size++) + len++; + + if (len == 0) { + if (number == 0) { + /* "0" - allow it */ + return TRUE; + } + + *bytes += number*1024; /* assume kilobytes */ + return FALSE; + } + + if (g_strncasecmp(desc, "gbytes", len) == 0) + *bytes += number * 1024*1024*1024; + if (g_strncasecmp(desc, "mbytes", len) == 0) + *bytes += number * 1024*1024; + if (g_strncasecmp(desc, "kbytes", len) == 0) + *bytes += number * 1024; + if (g_strncasecmp(desc, "bytes", len) == 0) + *bytes += number; + + /* skip punctuation */ + while (*size != '\0' && i_ispunct(*size)) + size++; + } + + return TRUE; +} diff --git a/src/core/misc.h b/src/core/misc.h index 46f91bb8..7eee01a2 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -105,4 +105,8 @@ char *escape_string(const char *str); int nearest_power(int num); +/* Returns TRUE / FALSE */ +int parse_time_interval(const char *time, int *msecs); +int parse_size(const char *size, int *bytes); + #endif diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index c7b5dd45..beeddc94 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -461,14 +461,14 @@ static void sig_chat_protocol_deinit(CHAT_PROTOCOL_REC *proto) static void read_settings(void) { - reconnect_time = settings_get_int("server_reconnect_time"); - connect_timeout = settings_get_int("server_connect_timeout"); + reconnect_time = settings_get_time("server_reconnect_time")/1000; + connect_timeout = settings_get_time("server_connect_timeout")/1000; } void servers_reconnect_init(void) { - settings_add_int("server", "server_reconnect_time", 300); - settings_add_int("server", "server_connect_timeout", 300); + settings_add_time("server", "server_reconnect_time", "5min"); + settings_add_time("server", "server_connect_timeout", "5min"); reconnects = NULL; last_reconnect_tag = 0; diff --git a/src/core/settings.c b/src/core/settings.c index d99757e0..c93a11d6 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -21,6 +21,7 @@ #include "module.h" #include "signals.h" #include "commands.h" +#include "levels.h" #include "misc.h" #include "lib-config/iconfig.h" @@ -29,6 +30,8 @@ #include <signal.h> +#define SETTINGS_AUTOSAVE_TIMEOUT (1000*60*60) /* 1 hour */ + CONFIG_REC *mainconfig; static GString *last_errors; @@ -60,83 +63,107 @@ static SETTINGS_REC *settings_find(const char *key) return rec; } -const char *settings_get_str(const char *key) +static SETTINGS_REC *settings_get(const char *key, SettingType type) { SETTINGS_REC *rec; - CONFIG_NODE *setnode, *node; rec = settings_find(key); - g_return_val_if_fail(rec != NULL, NULL); + if (rec == NULL) { + g_warning("settings_get(%s) : not found", key); + return 0; + } + if (type != -1 && rec->type != type) { + g_warning("settings_get(%s) : invalid type", key); + return 0; + } + + return rec; +} + +static const char * +settings_get_str_type(const char *key, SettingType type) +{ + SETTINGS_REC *rec; + CONFIG_NODE *node; - setnode = iconfig_node_traverse("settings", FALSE); - if (setnode == NULL) - return rec->def; + rec = settings_get(key, type); + if (rec == NULL) return NULL; - node = config_node_section(setnode, rec->module, -1); - return node == NULL ? rec->def : - config_node_get_str(node, key, rec->def); + node = iconfig_node_traverse("settings", FALSE); + node = node == NULL ? NULL : config_node_section(node, rec->module, -1); + + return node == NULL ? rec->default_value.v_string : + config_node_get_str(node, key, rec->default_value.v_string); +} + +const char *settings_get_str(const char *key) +{ + return settings_get_str_type(key, -1); } int settings_get_int(const char *key) { SETTINGS_REC *rec; - CONFIG_NODE *setnode, *node; - int def; + CONFIG_NODE *node; - rec = settings_find(key); - g_return_val_if_fail(rec != NULL, 0); - def = GPOINTER_TO_INT(rec->def); + rec = settings_get(key, SETTING_TYPE_INT); + if (rec == NULL) return 0; - setnode = iconfig_node_traverse("settings", FALSE); - if (setnode == NULL) - return def; + node = iconfig_node_traverse("settings", FALSE); + node = node == NULL ? NULL : config_node_section(node, rec->module, -1); - node = config_node_section(setnode, rec->module, -1); - return node == NULL ? def : - config_node_get_int(node, key, def); + return node == NULL ? rec->default_value.v_int : + config_node_get_int(node, key, rec->default_value.v_int); } int settings_get_bool(const char *key) { SETTINGS_REC *rec; - CONFIG_NODE *setnode, *node; - int def; + CONFIG_NODE *node; - rec = settings_find(key); - g_return_val_if_fail(rec != NULL, 0); - def = GPOINTER_TO_INT(rec->def); + rec = settings_get(key, SETTING_TYPE_BOOLEAN); + if (rec == NULL) return FALSE; - setnode = iconfig_node_traverse("settings", FALSE); - if (setnode == NULL) - return def; + node = iconfig_node_traverse("settings", FALSE); + node = node == NULL ? NULL : config_node_section(node, rec->module, -1); - node = config_node_section(setnode, rec->module, -1); - return node == NULL ? def : - config_node_get_bool(node, key, def); + return node == NULL ? rec->default_value.v_bool : + config_node_get_bool(node, key, rec->default_value.v_bool); } -void settings_add_str_module(const char *module, const char *section, - const char *key, const char *def) +int settings_get_time(const char *key) { - SETTINGS_REC *rec; + const char *str; + int msecs; - g_return_if_fail(key != NULL); - g_return_if_fail(section != NULL); + str = settings_get_str_type(key, SETTING_TYPE_TIME); + if (str != NULL && !parse_time_interval(str, &msecs)) + g_warning("settings_get_size(%s) : Invalid time '%s'", key, str); + return str == NULL ? 0 : msecs; +} - rec = g_hash_table_lookup(settings, key); - g_return_if_fail(rec == NULL); +int settings_get_level(const char *key) +{ + const char *str; + + str = settings_get_str_type(key, SETTING_TYPE_LEVEL); + return str == NULL ? 0 : level2bits(str); +} - rec = g_new0(SETTINGS_REC, 1); - rec->module = g_strdup(module); - rec->key = g_strdup(key); - rec->section = g_strdup(section); - rec->def = def == NULL ? NULL : g_strdup(def); +int settings_get_size(const char *key) +{ + const char *str; + int bytes; - g_hash_table_insert(settings, rec->key, rec); + str = settings_get_str_type(key, SETTING_TYPE_SIZE); + if (str != NULL && !parse_size(str, &bytes)) + g_warning("settings_get_size(%s) : Invalid size '%s'", key, str); + return str == NULL ? 0 : bytes; } -void settings_add_int_module(const char *module, const char *section, - const char *key, int def) +static void settings_add(const char *module, const char *section, + const char *key, SettingType type, + SettingValue *default_value) { SETTINGS_REC *rec; @@ -144,49 +171,106 @@ void settings_add_int_module(const char *module, const char *section, g_return_if_fail(section != NULL); rec = g_hash_table_lookup(settings, key); - g_return_if_fail(rec == NULL); + if (rec != NULL) { + /* Already exists, make sure it's correct type */ + if (rec->type != type) { + g_warning("Trying to add already existing " + "setting '%s' with different type.", key); + return; + } + } else { + rec = g_new(SETTINGS_REC, 1); + rec->module = g_strdup(module); + rec->key = g_strdup(key); + rec->section = g_strdup(section); + rec->type = type; + + rec->default_value = *default_value; + if (type != SETTING_TYPE_INT && + type != SETTING_TYPE_BOOLEAN) { + rec->default_value.v_string = + g_strdup(default_value->v_string); + } - rec = g_new0(SETTINGS_REC, 1); - rec->module = g_strdup(module); - rec->type = SETTING_TYPE_INT; - rec->key = g_strdup(key); - rec->section = g_strdup(section); - rec->def = GINT_TO_POINTER(def); + g_hash_table_insert(settings, rec->key, rec); + } - g_hash_table_insert(settings, rec->key, rec); + rec->refcount++; +} + +void settings_add_str_module(const char *module, const char *section, + const char *key, const char *def) +{ + SettingValue default_value; + + default_value.v_string = (char *) def; + settings_add(module, section, key, SETTING_TYPE_STRING, &default_value); +} + +void settings_add_int_module(const char *module, const char *section, + const char *key, int def) +{ + SettingValue default_value; + + default_value.v_int = def; + settings_add(module, section, key, SETTING_TYPE_INT, &default_value); } void settings_add_bool_module(const char *module, const char *section, const char *key, int def) { - SETTINGS_REC *rec; + SettingValue default_value; - g_return_if_fail(key != NULL); - g_return_if_fail(section != NULL); + default_value.v_bool = def; + settings_add(module, section, key, SETTING_TYPE_BOOLEAN, + &default_value); +} - rec = g_hash_table_lookup(settings, key); - g_return_if_fail(rec == NULL); +void settings_add_time_module(const char *module, const char *section, + const char *key, const char *def) +{ + SettingValue default_value; - rec = g_new0(SETTINGS_REC, 1); - rec->module = g_strdup(module); - rec->type = SETTING_TYPE_BOOLEAN; - rec->key = g_strdup(key); - rec->section = g_strdup(section); - rec->def = GINT_TO_POINTER(def); + default_value.v_string = (char *) def; + settings_add(module, section, key, SETTING_TYPE_TIME, &default_value); +} - g_hash_table_insert(settings, rec->key, rec); +void settings_add_level_module(const char *module, const char *section, + const char *key, const char *def) +{ + SettingValue default_value; + + default_value.v_string = (char *) def; + settings_add(module, section, key, SETTING_TYPE_LEVEL, &default_value); +} + +void settings_add_size_module(const char *module, const char *section, + const char *key, const char *def) +{ + SettingValue default_value; + + default_value.v_string = (char *) def; + settings_add(module, section, key, SETTING_TYPE_SIZE, &default_value); } static void settings_destroy(SETTINGS_REC *rec) { if (rec->type == SETTING_TYPE_STRING) - g_free_not_null(rec->def); + g_free(rec->default_value.v_string); g_free(rec->module); g_free(rec->section); g_free(rec->key); g_free(rec); } +static void settings_unref(SETTINGS_REC *rec) +{ + if (--rec->refcount == 0) { + g_hash_table_remove(settings, rec->key); + settings_destroy(rec); + } +} + void settings_remove(const char *key) { SETTINGS_REC *rec; @@ -194,17 +278,15 @@ void settings_remove(const char *key) g_return_if_fail(key != NULL); rec = g_hash_table_lookup(settings, key); - if (rec == NULL) return; - - g_hash_table_remove(settings, key); - settings_destroy(rec); + if (rec != NULL) + settings_unref(rec); } static int settings_remove_hash(const char *key, SETTINGS_REC *rec, const char *module) { if (strcmp(rec->module, module) == 0) { - settings_destroy(rec); + settings_unref(rec); return TRUE; } @@ -226,7 +308,10 @@ static CONFIG_NODE *settings_get_node(const char *key) g_return_val_if_fail(key != NULL, NULL); rec = g_hash_table_lookup(settings, key); - g_return_val_if_fail(rec != NULL, NULL); + if (rec == NULL) { + g_warning("Changing unknown setting '%s'", key); + return NULL; + } node = iconfig_node_traverse("settings", TRUE); return config_node_section(node, rec->module, NODE_TYPE_BLOCK); @@ -247,7 +332,35 @@ void settings_set_bool(const char *key, int value) iconfig_node_set_bool(settings_get_node(key), key, value); } -int settings_get_type(const char *key) +int settings_set_time(const char *key, const char *value) +{ + int msecs; + + if (!parse_time_interval(value, &msecs)) + return FALSE; + + iconfig_node_set_str(settings_get_node(key), key, value); + return TRUE; +} + +int settings_set_level(const char *key, const char *value) +{ + iconfig_node_set_str(settings_get_node(key), key, value); + return TRUE; +} + +int settings_set_size(const char *key, const char *value) +{ + int size; + + if (!parse_size(value, &size)) + return FALSE; + + iconfig_node_set_str(settings_get_node(key), key, value); + return TRUE; +} + +SettingType settings_get_type(const char *key) { SETTINGS_REC *rec; @@ -621,7 +734,8 @@ void settings_init(void) init_configfile(); settings_add_bool("misc", "settings_autosave", TRUE); - timeout_tag = g_timeout_add(1000*60*60, (GSourceFunc) sig_autosave, NULL); + timeout_tag = g_timeout_add(SETTINGS_AUTOSAVE_TIMEOUT, + (GSourceFunc) sig_autosave, NULL); signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished); signal_add("gui exit", (SIGNAL_FUNC) sig_autosave); } diff --git a/src/core/settings.h b/src/core/settings.h index fdff3801..df4a95ab 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -1,18 +1,30 @@ #ifndef __SETTINGS_H #define __SETTINGS_H -enum { +typedef enum { SETTING_TYPE_STRING, SETTING_TYPE_INT, - SETTING_TYPE_BOOLEAN -}; + SETTING_TYPE_BOOLEAN, + SETTING_TYPE_TIME, + SETTING_TYPE_LEVEL, + SETTING_TYPE_SIZE +} SettingType; + +typedef union { + char *v_string; + int v_int; + unsigned int v_bool:1; +} SettingValue; typedef struct { - char *module; - int type; + int refcount; + + char *module; char *key; char *section; - void *def; + + SettingType type; + SettingValue default_value; } SETTINGS_REC; /* macros for handling the default Irssi configuration */ @@ -40,6 +52,9 @@ extern const char *default_config; const char *settings_get_str(const char *key); int settings_get_int(const char *key); int settings_get_bool(const char *key); +int settings_get_time(const char *key); /* as milliseconds */ +int settings_get_level(const char *key); +int settings_get_size(const char *key); /* as bytes */ /* Functions to add/remove settings */ void settings_add_str_module(const char *module, const char *section, @@ -48,6 +63,12 @@ void settings_add_int_module(const char *module, const char *section, const char *key, int def); void settings_add_bool_module(const char *module, const char *section, const char *key, int def); +void settings_add_time_module(const char *module, const char *section, + const char *key, const char *def); +void settings_add_level_module(const char *module, const char *section, + const char *key, const char *def); +void settings_add_size_module(const char *module, const char *section, + const char *key, const char *def); void settings_remove(const char *key); void settings_remove_module(const char *module); @@ -57,13 +78,22 @@ void settings_remove_module(const char *module); settings_add_int_module(MODULE_NAME, section, key, def) #define settings_add_bool(section, key, def) \ settings_add_bool_module(MODULE_NAME, section, key, def) +#define settings_add_time(section, key, def) \ + settings_add_time_module(MODULE_NAME, section, key, def) +#define settings_add_level(section, key, def) \ + settings_add_level_module(MODULE_NAME, section, key, def) +#define settings_add_size(section, key, def) \ + settings_add_size_module(MODULE_NAME, section, key, def) void settings_set_str(const char *key, const char *value); void settings_set_int(const char *key, int value); void settings_set_bool(const char *key, int value); +int settings_set_time(const char *key, const char *value); +int settings_set_level(const char *key, const char *value); +int settings_set_size(const char *key, const char *value); /* Get the type (SETTING_TYPE_xxx) of `key' */ -int settings_get_type(const char *key); +SettingType settings_get_type(const char *key); /* Get all settings sorted by section. Free the result with g_slist_free() */ GSList *settings_get_sorted(void); /* Get the record of the setting */ diff --git a/src/core/write-buffer.c b/src/core/write-buffer.c index 1c3eef82..eec306ae 100644 --- a/src/core/write-buffer.c +++ b/src/core/write-buffer.c @@ -134,17 +134,14 @@ static int flush_timeout(void) static void read_settings(void) { - int msecs; - write_buffer_flush(); - write_buffer_max_blocks = settings_get_int("write_buffer_kb") * - 1024/BUFFER_BLOCK_SIZE; + write_buffer_max_blocks = + settings_get_size("write_buffer_size") / BUFFER_BLOCK_SIZE; - if (settings_get_int("write_buffer_mins") > 0) { - msecs = settings_get_int("write_buffer_mins")*60*1000; + if (settings_get_time("write_buffer_timeout") > 0) { if (timeout_tag == -1) { - timeout_tag = g_timeout_add(msecs, + timeout_tag = g_timeout_add(settings_get_time("write_buffer_timeout"), (GSourceFunc) flush_timeout, NULL); } @@ -161,8 +158,8 @@ static void cmd_flushbuffer(void) void write_buffer_init(void) { - settings_add_int("misc", "write_buffer_mins", 0); - settings_add_int("misc", "write_buffer_kb", 0); + settings_add_time("misc", "write_buffer_timeout", "0"); + settings_add_size("misc", "write_buffer_size", "0"); buffers = g_hash_table_new((GHashFunc) g_direct_hash, (GCompareFunc) g_direct_equal); diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 49c8db87..e6fdb6fe 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -153,11 +153,11 @@ void fe_common_core_init(void) args_register(options); settings_add_bool("lookandfeel", "timestamps", TRUE); - settings_add_str("lookandfeel", "timestamp_level", "ALL"); - settings_add_int("lookandfeel", "timestamp_timeout", 0); + settings_add_level("lookandfeel", "timestamp_level", "ALL"); + settings_add_time("lookandfeel", "timestamp_timeout", 0); settings_add_bool("lookandfeel", "bell_beeps", FALSE); - settings_add_str("lookandfeel", "beep_msg_level", ""); + settings_add_level("lookandfeel", "beep_msg_level", ""); settings_add_bool("lookandfeel", "beep_when_window_active", TRUE); settings_add_bool("lookandfeel", "beep_when_away", TRUE); diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index b599c810..56c2dac3 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -47,7 +47,8 @@ static int ret_texts[] = { TXT_CHAN_NOT_FOUND, TXT_CHAN_NOT_SYNCED, TXT_ILLEGAL_PROTO, - TXT_NOT_GOOD_IDEA + TXT_NOT_GOOD_IDEA, + CMDERR_INVALID_TIME }; int command_hide_output; diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c index 4621ab26..83bc1584 100644 --- a/src/fe-common/core/fe-ignore.c +++ b/src/fe-common/core/fe-ignore.c @@ -115,7 +115,7 @@ static void cmd_ignore(const char *data) char *patternarg, *chanarg, *mask, *levels, *timestr; char **channels; void *free_arg; - int new_ignore; + int new_ignore, msecs; if (*data == '\0') { cmd_ignore_show(); @@ -132,6 +132,13 @@ static void cmd_ignore(const char *data) if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); if (*levels == '\0') levels = "ALL"; + msecs = 0; + timestr = g_hash_table_lookup(optlist, "time"); + if (timestr != NULL) { + if (!parse_time_interval(timestr, &msecs)) + cmd_return_error(CMDERR_INVALID_TIME); + } + if (active_win->active_server != NULL && server_ischannel(active_win->active_server, mask)) { chanarg = mask; @@ -173,9 +180,8 @@ static void cmd_ignore(const char *data) rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL; rec->fullword = g_hash_table_lookup(optlist, "full") != NULL; rec->replies = g_hash_table_lookup(optlist, "replies") != NULL; - timestr = g_hash_table_lookup(optlist, "time"); - if (timestr != NULL) - rec->unignore_time = time(NULL)+atoi(timestr); + if (msecs != 0) + rec->unignore_time = time(NULL)+msecs/1000; if (new_ignore) ignore_add_rec(rec); diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 1db74fe1..1b88364e 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -671,7 +671,7 @@ static void read_settings(void) autolog_path = settings_get_str("autolog_path"); autolog_level = !settings_get_bool("autolog") ? 0 : - level2bits(settings_get_str("autolog_level")); + settings_get_level("autolog_level"); if (old_autolog && !autolog_level) autologs_close_all(); @@ -704,7 +704,7 @@ void fe_log_init(void) settings_add_bool("log", "autolog", FALSE); settings_add_bool("log", "autolog_colors", FALSE); settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log"); - settings_add_str("log", "autolog_level", "all -crap -clientcrap -ctcps"); + settings_add_level("log", "autolog_level", "all -crap -clientcrap -ctcps"); settings_add_str("log", "log_theme", ""); autolog_level = 0; diff --git a/src/fe-common/core/fe-queries.c b/src/fe-common/core/fe-queries.c index 8345d52f..f48e37e9 100644 --- a/src/fe-common/core/fe-queries.c +++ b/src/fe-common/core/fe-queries.c @@ -340,8 +340,8 @@ static void sig_message_private(SERVER_REC *server, const char *msg, static void read_settings(void) { - querycreate_level = level2bits(settings_get_str("autocreate_query_level")); - query_auto_close = settings_get_int("autoclose_query"); + querycreate_level = settings_get_level("autocreate_query_level"); + query_auto_close = settings_get_time("autoclose_query")/1000; if (query_auto_close > 0 && queryclose_tag == -1) queryclose_tag = g_timeout_add(5000, (GSourceFunc) sig_query_autoclose, NULL); else if (query_auto_close <= 0 && queryclose_tag != -1) { @@ -352,9 +352,9 @@ static void read_settings(void) void fe_queries_init(void) { - settings_add_str("lookandfeel", "autocreate_query_level", "MSGS DCCMSGS"); + settings_add_level("lookandfeel", "autocreate_query_level", "MSGS DCCMSGS"); settings_add_bool("lookandfeel", "autocreate_own_query", TRUE); - settings_add_int("lookandfeel", "autoclose_query", 0); + settings_add_time("lookandfeel", "autoclose_query", "0"); queryclose_tag = -1; read_settings(); diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index 7fb512e8..8dba8f73 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -45,6 +45,9 @@ static void set_print(SETTINGS_REC *rec) value = value_int; break; case SETTING_TYPE_STRING: + case SETTING_TYPE_TIME: + case SETTING_TYPE_LEVEL: + case SETTING_TYPE_SIZE: value = settings_get_str(rec->key); break; default: @@ -106,20 +109,38 @@ static void cmd_set(char *data) if (clear) settings_set_bool(key, FALSE); else if (set_default) - settings_set_bool(key, GPOINTER_TO_INT(rec->def)); + settings_set_bool(key, rec->default_value.v_bool); else set_boolean(key, value); break; case SETTING_TYPE_INT: settings_set_int(key, clear ? 0 : - set_default ? GPOINTER_TO_INT(rec->def) : + set_default ? rec->default_value.v_int : atoi(value)); break; case SETTING_TYPE_STRING: settings_set_str(key, clear ? "" : - set_default ? rec->def : + set_default ? rec->default_value.v_string : value); break; + case SETTING_TYPE_TIME: + if (!settings_set_time(key, clear ? "0" : + set_default ? rec->default_value.v_string : value)) + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_INVALID_TIME); + break; + case SETTING_TYPE_LEVEL: + if (!settings_set_level(key, clear ? "" : + set_default ? rec->default_value.v_string : value)) + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_INVALID_LEVEL); + break; + case SETTING_TYPE_SIZE: + if (!settings_set_size(key, clear ? "0" : + set_default ? rec->default_value.v_string : value)) + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_INVALID_SIZE); + break; } signal_emit("setup changed", 0); } diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c index dc264d65..6eb4707a 100644 --- a/src/fe-common/core/fe-windows.c +++ b/src/fe-common/core/fe-windows.c @@ -70,7 +70,7 @@ WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic) rec = g_new0(WINDOW_REC, 1); rec->refnum = window_get_new_refnum(); - rec->level = level2bits(settings_get_str("window_default_level")); + rec->level = settings_get_level("window_default_level"); windows = g_slist_prepend(windows, rec); signal_emit("window created", 2, rec, GINT_TO_POINTER(automatic)); @@ -646,7 +646,7 @@ void windows_init(void) settings_add_bool("lookandfeel", "window_auto_change", FALSE); settings_add_bool("lookandfeel", "windows_auto_renumber", TRUE); settings_add_bool("lookandfeel", "window_check_level_first", FALSE); - settings_add_str("lookandfeel", "window_default_level", "NONE"); + settings_add_level("lookandfeel", "window_default_level", "NONE"); read_settings(); signal_add("server looking", (SIGNAL_FUNC) sig_server_connected); diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index 06464894..c6bc72a3 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -1091,11 +1091,9 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text) static void read_settings(void) { timestamp_level = settings_get_bool("timestamps") ? MSGLEVEL_ALL : 0; - if (timestamp_level > 0) { - timestamp_level = - level2bits(settings_get_str("timestamp_level")); - } - timestamp_timeout = settings_get_int("timestamp_timeout"); + if (timestamp_level > 0) + timestamp_level = settings_get_level("timestamp_level"); + timestamp_timeout = settings_get_time("timestamp_timeout")/1000; hide_server_tags = settings_get_bool("hide_server_tags"); hide_text_style = settings_get_bool("hide_text_style"); diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c index 9749504b..54cb12a1 100644 --- a/src/fe-common/core/hilight-text.c +++ b/src/fe-common/core/hilight-text.c @@ -676,14 +676,14 @@ static void hilight_nick_cache(GHashTable *list, CHANNEL_REC *channel, static void read_settings(void) { - default_hilight_level = level2bits(settings_get_str("hilight_level")); + default_hilight_level = settings_get_level("hilight_level"); } void hilight_text_init(void) { settings_add_str("lookandfeel", "hilight_color", "%Y"); settings_add_str("lookandfeel", "hilight_act_color", "%M"); - settings_add_str("lookandfeel", "hilight_level", "PUBLIC DCCMSGS"); + settings_add_level("lookandfeel", "hilight_level", "PUBLIC DCCMSGS"); read_settings(); diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 2d4f02e1..c70f1e04 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -214,6 +214,9 @@ FORMAT_REC fecommon_core_formats[] = { { "chan_not_synced", "Channel not fully synchronized yet, try again after a while", 0 }, { "illegal_proto", "Command isn't designed for the chat protocol of the active server", 0 }, { "not_good_idea", "Doing this is not a good idea. Add -YES option to command if you really mean it", 0 }, + { "invalid_time", "Invalid timestamp", 0 }, + { "invalid_level", "Invalid message level", 0 }, + { "invalid_size", "Invalid size", 0 }, /* ---- */ { NULL, "Themes", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 7cd46bab..5f28f0e1 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -183,6 +183,9 @@ enum { TXT_CHAN_NOT_SYNCED, TXT_ILLEGAL_PROTO, TXT_NOT_GOOD_IDEA, + TXT_INVALID_TIME, + TXT_INVALID_LEVEL, + TXT_INVALID_SIZE, TXT_FILL_11, diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c index e32b5943..6cc64081 100644 --- a/src/fe-common/core/printtext.c +++ b/src/fe-common/core/printtext.c @@ -474,7 +474,7 @@ static void sig_gui_dialog(const char *type, const char *text) static void read_settings(void) { - beep_msg_level = level2bits(settings_get_str("beep_msg_level")); + beep_msg_level = settings_get_level("beep_msg_level"); beep_when_away = settings_get_bool("beep_when_away"); beep_when_window_active = settings_get_bool("beep_when_window_active"); } diff --git a/src/fe-common/core/window-activity.c b/src/fe-common/core/window-activity.c index 883821f0..64b0aad3 100644 --- a/src/fe-common/core/window-activity.c +++ b/src/fe-common/core/window-activity.c @@ -138,18 +138,18 @@ static void read_settings(void) g_strsplit(targets, " ", -1); hide_level = MSGLEVEL_NEVER | MSGLEVEL_NO_ACT | - level2bits(settings_get_str("activity_hide_level")); - msg_level = level2bits(settings_get_str("activity_msg_level")); + settings_get_level("activity_hide_level"); + msg_level = settings_get_level("activity_msg_level"); hilight_level = MSGLEVEL_HILIGHT | - level2bits(settings_get_str("activity_hilight_level")); + settings_get_level("activity_hilight_level"); } void window_activity_init(void) { settings_add_str("lookandfeel", "activity_hide_targets", ""); - settings_add_str("lookandfeel", "activity_hide_level", ""); - settings_add_str("lookandfeel", "activity_msg_level", "PUBLIC"); - settings_add_str("lookandfeel", "activity_hilight_level", "MSGS DCCMSGS"); + settings_add_level("lookandfeel", "activity_hide_level", ""); + settings_add_level("lookandfeel", "activity_msg_level", "PUBLIC"); + settings_add_level("lookandfeel", "activity_hilight_level", "MSGS DCCMSGS"); read_settings(); signal_add("print text", (SIGNAL_FUNC) sig_hilight_text); diff --git a/src/fe-common/irc/dcc/fe-dcc-chat.c b/src/fe-common/irc/dcc/fe-dcc-chat.c index 3095fcfd..d2723c96 100644 --- a/src/fe-common/irc/dcc/fe-dcc-chat.c +++ b/src/fe-common/irc/dcc/fe-dcc-chat.c @@ -340,7 +340,7 @@ static void read_settings(void) { int level; - level = level2bits(settings_get_str("autocreate_query_level")); + level = settings_get_level("autocreate_query_level"); autocreate_dccquery = (level & MSGLEVEL_DCCMSGS) != 0; } diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c index 2d8a8cde..b4d223e9 100644 --- a/src/fe-text/gui-printtext.c +++ b/src/fe-text/gui-printtext.c @@ -30,7 +30,7 @@ #include "gui-windows.h" int mirc_colors[] = { 15, 0, 1, 2, 12, 4, 5, 6, 14, 10, 3, 11, 9, 13, 8, 7 }; -static int scrollback_lines, scrollback_hours, scrollback_burst_remove; +static int scrollback_lines, scrollback_time, scrollback_burst_remove; static int last_fg, last_bg, last_flags; static int next_xpos, next_ypos; @@ -120,7 +120,7 @@ static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view) LINE_REC *line; time_t old_time; - old_time = time(NULL)-(scrollback_hours*3600)+1; + old_time = time(NULL)-scrollback_time+1; if (view->buffer->lines_count >= scrollback_lines+scrollback_burst_remove) { /* remove lines by line count */ @@ -130,7 +130,7 @@ static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view) scrollback_lines == 0) { /* too new line, don't remove yet - also if scrollback_lines is 0, we want to check - only scrollback_hours setting. */ + only scrollback_time setting. */ break; } textbuffer_view_remove_line(view, line); @@ -302,7 +302,7 @@ static void sig_gui_printtext_finished(WINDOW_REC *window) static void read_settings(void) { scrollback_lines = settings_get_int("scrollback_lines"); - scrollback_hours = settings_get_int("scrollback_hours"); + scrollback_time = settings_get_time("scrollback_time")/1000; scrollback_burst_remove = settings_get_int("scrollback_burst_remove"); } @@ -314,7 +314,7 @@ void gui_printtext_init(void) (GCompareFunc) g_str_equal); settings_add_int("history", "scrollback_lines", 500); - settings_add_int("history", "scrollback_hours", 24); + settings_add_time("history", "scrollback_time", "day"); settings_add_int("history", "scrollback_burst_remove", 10); signal_add("gui print text", (SIGNAL_FUNC) sig_gui_print_text); diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c index fe74a748..fe9ca0e2 100644 --- a/src/fe-text/statusbar-items.c +++ b/src/fe-text/statusbar-items.c @@ -290,15 +290,16 @@ static void item_lag(SBAR_ITEM_REC *item, int get_size_only) int lag, lag_unknown; server = active_win == NULL ? NULL : active_win->active_server; - lag = get_lag(server, &lag_unknown)/10; + lag = get_lag(server, &lag_unknown); - if (lag <= 0 || lag < settings_get_int("lag_min_show")) { + if (lag <= 0 || lag < settings_get_time("lag_min_show")) { /* don't print the lag item */ if (get_size_only) item->min_size = item->max_size = 0; return; } + lag /= 10; last_lag = lag; last_lag_unknown = lag_unknown; @@ -321,8 +322,10 @@ static void lag_check_update(void) server = active_win == NULL ? NULL : active_win->active_server; lag = get_lag(server, &lag_unknown)/10; - if (lag < settings_get_int("lag_min_show")) - lag = 0; + if (lag < settings_get_time("lag_min_show")) + lag = 0; + else + lag /= 10; if (lag != last_lag || (lag > 0 && lag_unknown != last_lag_unknown)) statusbar_items_redraw("lag"); @@ -372,7 +375,7 @@ static void read_settings(void) void statusbar_items_init(void) { - settings_add_int("misc", "lag_min_show", 100); + settings_add_time("misc", "lag_min_show", "100msec"); settings_add_bool("lookandfeel", "actlist_moves", FALSE); statusbar_item_register("window", NULL, item_window_active); diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index e989b8fd..5a8d256d 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -137,6 +137,8 @@ static void text_chunk_line_free(TEXT_BUFFER_REC *buffer, LINE_REC *line) break; text = tmp-1; + } else if (*text == LINE_CMD_INDENT_FUNC) { + text += sizeof(int (*) ()); } } } diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index d7512de2..8c888ffe 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -736,7 +736,7 @@ static int knockout_timeout(void) return 1; } -/* SYNTAX: KNOCKOUT [<seconds>] <nicks> <reason> */ +/* SYNTAX: KNOCKOUT [<time>] <nicks> <reason> */ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, IRC_CHANNEL_REC *channel) { @@ -753,20 +753,21 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, if (!channel->wholist) cmd_return_error(CMDERR_CHAN_NOT_SYNCED); - if (is_numeric(data, ' ')) { + if (i_isdigit(*data)) { /* first argument is the timeout */ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &timeoutstr, &nicks, &reason)) return; - timeleft = atoi(timeoutstr); + + if (!parse_time_interval(timeoutstr, &timeleft)) + cmd_param_error(CMDERR_INVALID_TIME); } else { if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nicks, &reason)) return; - timeleft = 0; + timeleft = settings_get_time("knockout_time"); } - if (timeleft == 0) timeleft = settings_get_int("knockout_time"); if (*nicks == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); nicklist = g_strsplit(nicks, ",", -1); @@ -797,7 +798,7 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, else { /* create knockout record */ rec = g_new(KNOCKOUT_REC, 1); - rec->unban_time = time(NULL)+timeleft; + rec->unban_time = time(NULL)+timeleft/1000; rec->channel = channel; rec->ban = banmasks; @@ -916,7 +917,7 @@ void irc_commands_init(void) tmpstr = g_string_new(NULL); settings_add_str("misc", "part_message", ""); - settings_add_int("misc", "knockout_time", 300); + settings_add_time("misc", "knockout_time", "5min"); settings_add_str("misc", "wall_format", "[Wall/$0] $1-"); settings_add_bool("misc", "kick_first_on_kickban", FALSE); diff --git a/src/irc/core/irc-servers-reconnect.c b/src/irc/core/irc-servers-reconnect.c index c2649f5e..7e66b255 100644 --- a/src/irc/core/irc-servers-reconnect.c +++ b/src/irc/core/irc-servers-reconnect.c @@ -88,7 +88,7 @@ static void event_nick_collision(IRC_SERVER_REC *server, const char *data) don't connect to the server more than once in every 10 seconds. */ new_connect = server->connect_time+10 - - settings_get_int("server_reconnect_time"); + settings_get_time("server_reconnect_time")/1000; if (server->connect_time > new_connect) server->connect_time = new_connect; diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index b1a7b007..fa3ded76 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -46,7 +46,7 @@ #define DEFAULT_MAX_MSGS 1 #define DEFAULT_USER_MODE "+i" -#define DEFAULT_CMD_QUEUE_SPEED 2200 +#define DEFAULT_CMD_QUEUE_SPEED "2200msec" #define DEFAULT_CMDS_MAX_AT_ONCE 5 #define DEFAULT_MAX_QUERY_CHANS 1 /* more and more IRC networks are using stupid ircds.. */ @@ -180,7 +180,7 @@ SERVER_REC *irc_server_init_connect(SERVER_CONNECT_REC *conn) } server->cmd_queue_speed = ircconn->cmd_queue_speed > 0 ? - ircconn->cmd_queue_speed : settings_get_int("cmd_queue_speed"); + ircconn->cmd_queue_speed : settings_get_time("cmd_queue_speed"); server->max_cmds_at_once = ircconn->max_cmds_at_once > 0 ? ircconn->max_cmds_at_once : settings_get_int("cmds_max_at_once"); server->max_query_chans = ircconn->max_query_chans > 0 ? @@ -587,7 +587,7 @@ static void event_empty(void) void irc_servers_init(void) { settings_add_str("misc", "usermode", DEFAULT_USER_MODE); - settings_add_int("flood", "cmd_queue_speed", DEFAULT_CMD_QUEUE_SPEED); + settings_add_time("flood", "cmd_queue_speed", DEFAULT_CMD_QUEUE_SPEED); settings_add_int("flood", "cmds_max_at_once", DEFAULT_CMDS_MAX_AT_ONCE); cmd_tag = g_timeout_add(500, (GSourceFunc) servers_cmd_timeout, NULL); diff --git a/src/irc/core/lag.c b/src/irc/core/lag.c index e919b3fc..7d4f51ed 100644 --- a/src/irc/core/lag.c +++ b/src/irc/core/lag.c @@ -88,8 +88,8 @@ static int sig_check_lag(void) time_t now; int lag_check_time, max_lag; - lag_check_time = settings_get_int("lag_check_time"); - max_lag = settings_get_int("lag_max_before_disconnect"); + lag_check_time = settings_get_time("lag_check_time")/1000; + max_lag = settings_get_time("lag_max_before_disconnect")/1000; if (lag_check_time <= 0) return 1; @@ -122,8 +122,8 @@ static int sig_check_lag(void) void lag_init(void) { - settings_add_int("misc", "lag_check_time", 60); - settings_add_int("misc", "lag_max_before_disconnect", 300); + settings_add_time("misc", "lag_check_time", "1min"); + settings_add_time("misc", "lag_max_before_disconnect", "5min"); timeout_tag = g_timeout_add(1000, (GSourceFunc) sig_check_lag, NULL); signal_add_first("lag pong", (SIGNAL_FUNC) lag_event_pong); diff --git a/src/irc/dcc/dcc-autoget.c b/src/irc/dcc/dcc-autoget.c index 87dd00d8..bf9a3b66 100644 --- a/src/irc/dcc/dcc-autoget.c +++ b/src/irc/dcc/dcc-autoget.c @@ -57,8 +57,8 @@ static void sig_dcc_request(GET_DCC_REC *dcc, const char *nickaddr) /* check file size limit, NOTE: it's still possible to send a bogus file size and then just send what ever sized file.. */ - max_size = settings_get_int("dcc_autoget_max_size"); - if (max_size > 0 && (uoff_t)max_size*1024 < dcc->size) + max_size = settings_get_size("dcc_autoget_max_size"); + if (max_size > 0 && (uoff_t)max_size < dcc->size) return; /* ok. but do we want/need to resume? */ @@ -77,7 +77,7 @@ void dcc_autoget_init(void) settings_add_bool("dcc", "dcc_autoget", FALSE); settings_add_bool("dcc", "dcc_autoaccept_lowports", FALSE); settings_add_bool("dcc", "dcc_autoresume", FALSE); - settings_add_int("dcc", "dcc_autoget_max_size", 0); + settings_add_size("dcc", "dcc_autoget_max_size", 0); settings_add_str("dcc", "dcc_autoget_masks", ""); signal_add_last("dcc request", (SIGNAL_FUNC) sig_dcc_request); diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c index 44ef3f20..e3e04107 100644 --- a/src/irc/dcc/dcc.c +++ b/src/irc/dcc/dcc.c @@ -420,7 +420,7 @@ static int dcc_timeout_func(void) GSList *tmp, *next; time_t now; - now = time(NULL)-settings_get_int("dcc_timeout"); + now = time(NULL)-settings_get_time("dcc_timeout")/1000; for (tmp = dcc_conns; tmp != NULL; tmp = next) { DCC_REC *dcc = tmp->data; @@ -514,7 +514,7 @@ void irc_dcc_init(void) dcc_timeouttag = g_timeout_add(1000, (GSourceFunc) dcc_timeout_func, NULL); settings_add_str("dcc", "dcc_port", "0"); - settings_add_int("dcc", "dcc_timeout", 300); + settings_add_time("dcc", "dcc_timeout", "5min"); settings_add_str("dcc", "dcc_own_ip", ""); signal_add("event connected", (SIGNAL_FUNC) sig_connected); diff --git a/src/irc/flood/autoignore.c b/src/irc/flood/autoignore.c index 7d409b6c..f029a39f 100644 --- a/src/irc/flood/autoignore.c +++ b/src/irc/flood/autoignore.c @@ -32,7 +32,8 @@ void autoignore_update(IGNORE_REC *rec, int level) { rec->level |= level; - rec->unignore_time = time(NULL)+settings_get_int("autoignore_time"); + rec->unignore_time = time(NULL) + + settings_get_time("autoignore_time")/1000; ignore_update_rec(rec); } @@ -46,7 +47,8 @@ void autoignore_add(IRC_SERVER_REC *server, char *mask, int level) rec->mask = g_strdup(mask); rec->servertag = g_strdup(server->tag); rec->level = level; - rec->unignore_time = time(NULL)+settings_get_int("autoignore_time"); + rec->unignore_time = time(NULL) + + settings_get_time("autoignore_time")/1000; ignore_add_rec(rec); } @@ -60,7 +62,7 @@ static void sig_flood(IRC_SERVER_REC *server, const char *nick, const char *host g_return_if_fail(IS_IRC_SERVER(server)); level = GPOINTER_TO_INT(levelp); - check_level = level2bits(settings_get_str("autoignore_level")); + check_level = settings_get_level("autoignore_level"); mask = g_strdup_printf("%s!%s", nick, host); if (level & check_level) { @@ -75,8 +77,8 @@ static void sig_flood(IRC_SERVER_REC *server, const char *nick, const char *host void autoignore_init(void) { - settings_add_int("flood", "autoignore_time", 300); - settings_add_str("flood", "autoignore_level", ""); + settings_add_time("flood", "autoignore_time", "5min"); + settings_add_level("flood", "autoignore_level", ""); signal_add("flood", (SIGNAL_FUNC) sig_flood); } diff --git a/src/irc/notifylist/notify-commands.c b/src/irc/notifylist/notify-commands.c index c51f33f3..1fb485e3 100644 --- a/src/irc/notifylist/notify-commands.c +++ b/src/irc/notifylist/notify-commands.c @@ -26,9 +26,7 @@ #include "notifylist.h" -#define DEFAULT_NOTIFY_IDLE_TIME 60 - -/* SYNTAX: NOTIFY [-away] [-idle [<minutes>]] <mask> [<ircnets>] */ +/* SYNTAX: NOTIFY [-away] [-idle [<time>]] <mask> [<ircnets>] */ static void cmd_notify(gchar *data) { GHashTable *optlist; @@ -46,14 +44,16 @@ static void cmd_notify(gchar *data) idletime = g_hash_table_lookup(optlist, "idle"); if (idletime == NULL) idle_check_time = 0; + else if (*idletime == '\0') + idle_check_time = settings_get_time("notify_idle_time"); else { - idle_check_time = is_numeric(idletime, 0) ? (atoi(idletime)*60) : - (settings_get_int("notify_idle_time")*60); + if (!parse_time_interval(idletime, &idle_check_time)) + cmd_return_error(CMDERR_INVALID_TIME); } away_check = g_hash_table_lookup(optlist, "away") != NULL; notifylist_remove(mask); - notifylist_add(mask, ircnets, away_check, idle_check_time); + notifylist_add(mask, ircnets, away_check, idle_check_time/1000); cmd_params_free(free_arg); } @@ -77,11 +77,11 @@ static void cmd_unnotify(const char *data) void notifylist_commands_init(void) { - settings_add_int("misc", "notify_idle_time", DEFAULT_NOTIFY_IDLE_TIME); + settings_add_time("misc", "notify_idle_time", "hour"); command_bind("notify", NULL, (SIGNAL_FUNC) cmd_notify); command_bind("unnotify", NULL, (SIGNAL_FUNC) cmd_unnotify); - command_set_options("notify", "@idle away"); + command_set_options("notify", "-idle away"); } void notifylist_commands_deinit(void) diff --git a/src/irc/notifylist/notify-ison.c b/src/irc/notifylist/notify-ison.c index 2de398a1..e27e3d60 100644 --- a/src/irc/notifylist/notify-ison.c +++ b/src/irc/notifylist/notify-ison.c @@ -29,8 +29,8 @@ #include "notifylist.h" -#define DEFAULT_NOTIFY_CHECK_TIME 60 -#define DEFAULT_NOTIFY_WHOIS_TIME (60*5) +#define DEFAULT_NOTIFY_CHECK_TIME "1min" +#define DEFAULT_NOTIFY_WHOIS_TIME "5min" typedef struct { char *nick; @@ -321,15 +321,16 @@ static void event_ison(IRC_SERVER_REC *server, const char *data) static void read_settings(void) { if (notify_tag != -1) g_source_remove(notify_tag); - notify_tag = g_timeout_add(1000*settings_get_int("notify_check_time"), (GSourceFunc) notifylist_timeout_func, NULL); + notify_tag = g_timeout_add(settings_get_time("notify_check_time"), + (GSourceFunc) notifylist_timeout_func, NULL); - notify_whois_time = settings_get_int("notify_whois_time"); + notify_whois_time = settings_get_time("notify_whois_time")/1000; } void notifylist_ison_init(void) { - settings_add_int("misc", "notify_check_time", DEFAULT_NOTIFY_CHECK_TIME); - settings_add_int("misc", "notify_whois_time", DEFAULT_NOTIFY_WHOIS_TIME); + settings_add_time("misc", "notify_check_time", DEFAULT_NOTIFY_CHECK_TIME); + settings_add_time("misc", "notify_whois_time", DEFAULT_NOTIFY_WHOIS_TIME); notify_tag = -1; read_settings(); diff --git a/src/perl/common/Settings.xs b/src/perl/common/Settings.xs index a7c5e6f6..f545befd 100644 --- a/src/perl/common/Settings.xs +++ b/src/perl/common/Settings.xs @@ -99,6 +99,21 @@ settings_set_bool(key, value) char *key int value +int +settings_set_time(key, value) + char *key + char *value + +int +settings_set_level(key, value) + char *key + char *value + +int +settings_set_size(key, value) + char *key + char *value + void settings_add_str(section, key, def) char *section @@ -127,6 +142,33 @@ CODE: settings_add_bool_module(MODULE_NAME"/scripts", section, key, def); void +settings_add_time(section, key, def) + char *section + char *key + char *def +CODE: + perl_settings_add(key); + settings_add_time_module(MODULE_NAME"/scripts", section, key, def); + +void +settings_add_level(section, key, def) + char *section + char *key + char *def +CODE: + perl_settings_add(key); + settings_add_level_module(MODULE_NAME"/scripts", section, key, def); + +void +settings_add_size(section, key, def) + char *section + char *key + char *def +CODE: + perl_settings_add(key); + settings_add_size_module(MODULE_NAME"/scripts", section, key, def); + +void settings_remove(key) char *key CODE: |