1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-12 17:14:46 +02:00

Condition Config: add minimum-version() and file-exists().

So: `@if minimum-version("6.2.4")` and `@if file-exists("filename")`.
This commit is contained in:
Bram Matthys
2026-03-22 18:41:30 +01:00
parent 9258875d0f
commit 17a8182efc
4 changed files with 83 additions and 1 deletions
+5
View File
@@ -12,6 +12,11 @@ This is work in progress and may not always be a stable version.
* New `@if module-exists("modulename")` to check if a module exists on
disk. You can use this with a subsequent `loadmodule` and config items,
this can be handy with 3rd party modules.
* New `@if minimum-version("6.2.4")` to check if the UnrealIRCd version
is at least the specified version.
* New `@if file-exists("filename")` to check if a file exists.
Paths are relative to the conf directory, or absolute if starting
with `/`.
### Changes:
* [GeoIP](https://www.unrealircd.org/docs/GeoIP):
+1
View File
@@ -1106,6 +1106,7 @@ extern MODVAR Client *remote_rehash_client;
extern MODVAR json_t *json_rehash_log;
extern MODVAR int debugfd;
extern void convert_to_absolute_path(char **path, const char *reldir);
extern char *convert_to_absolute_path_duplicate(char *path, char *reldir);
extern int has_user_mode(Client *acptr, char mode);
extern int has_channel_mode(Channel *channel, char mode);
extern int has_channel_mode_raw(Cmode_t m, char mode);
+1 -1
View File
@@ -1649,7 +1649,7 @@ struct AuthConfig {
* conf2 stuff -stskeeps
*/
typedef enum ConfigIfCondition { IF_DEFINED=1, IF_VALUE=2, IF_MODULE_LOADED=3, IF_MODULE_EXISTS=4} ConfigIfCondition;
typedef enum ConfigIfCondition { IF_DEFINED=1, IF_VALUE=2, IF_MODULE_LOADED=3, IF_MODULE_EXISTS=4, IF_MINIMUM_VERSION=5, IF_FILE_EXISTS=6} ConfigIfCondition;
struct ConditionalConfig
{
+76
View File
@@ -35,6 +35,10 @@ PreprocessorItem evaluate_preprocessor_if(char *statement, const char *filename,
* !module-loaded("something")
* module-exists("something")
* !module-exists("something")
* minimum-version("6.2.0")
* !minimum-version("6.2.0")
* file-exists("something")
* !file-exists("something")
* defined($XYZ)
* !defined($XYZ)
* We do not support && or || or anything else at this time.
@@ -110,6 +114,66 @@ PreprocessorItem evaluate_preprocessor_if(char *statement, const char *filename,
*cc_out = cc;
return PREPROCESSOR_IF;
} else
if (!strncmp(p, "minimum-version", 15))
{
p += 15;
skip_whitespace(&p);
if (*p != '(')
{
config_error("%s:%i: expected '(' for minimum-version(...",
filename, linenumber);
return PREPROCESSOR_ERROR;
}
p++;
skip_whitespace(&p);
if (*p == '"')
p++;
name = p;
read_until(&p, ")\"");
if (!*p)
{
config_error("%s:%i: invalid if statement (termination error): %s",
filename, linenumber, statement);
return PREPROCESSOR_ERROR;
}
*p = '\0';
cc = safe_alloc(sizeof(ConditionalConfig));
cc->condition = IF_MINIMUM_VERSION;
cc->negative = negative;
safe_strdup(cc->name, name);
*cc_out = cc;
return PREPROCESSOR_IF;
} else
if (!strncmp(p, "file-exists", 11))
{
p += 11;
skip_whitespace(&p);
if (*p != '(')
{
config_error("%s:%i: expected '(' for file-exists(...",
filename, linenumber);
return PREPROCESSOR_ERROR;
}
p++;
skip_whitespace(&p);
if (*p == '"')
p++;
name = p;
read_until(&p, ")\"");
if (!*p)
{
config_error("%s:%i: invalid if statement (termination error): %s",
filename, linenumber, statement);
return PREPROCESSOR_ERROR;
}
*p = '\0';
cc = safe_alloc(sizeof(ConditionalConfig));
cc->condition = IF_FILE_EXISTS;
cc->negative = negative;
safe_strdup(cc->name, name);
*cc_out = cc;
return PREPROCESSOR_IF;
} else
if (!strncmp(p, "defined", 7))
{
p += 7;
@@ -392,6 +456,18 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase)
if (file_exists(fullpath))
result = 1;
} else
if (cc->condition == IF_MINIMUM_VERSION)
{
if (strnatcasecmp(VERSIONONLY, cc->name) >= 0)
result = 1;
} else
if (cc->condition == IF_FILE_EXISTS)
{
char *fullpath = convert_to_absolute_path_duplicate(cc->name, CONFDIR);
if (file_exists(fullpath))
result = 1;
safe_free(fullpath);
} else
if (cc->condition == IF_DEFINED)
{
NameValuePrioList *d = find_config_define(cc->name);