From d35854691c75e311ca49ef4b0716968a1686f5ed Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 21 Jun 2026 01:59:32 +0200 Subject: [PATCH] allow to use multiple directories in html and txt templates remove from the config: templates_dir, templates_dir_default, txt_templates_dir, txt_templates_dir_default add to the config: html_templates_dirs - a list of directories with html templates txt_templates_dirs - a list of directories with txt templates We search from the last directory to the first one. --- winixd/core/config.cpp | 13 +++++++------ winixd/core/config.h | 14 ++++++++------ winixd/notify/notify.cpp | 6 +++--- winixd/templates/patterns.cpp | 15 +++++++++------ winixd/templates/patterns.h | 9 +++++---- winixd/templates/templates.cpp | 2 +- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/winixd/core/config.cpp b/winixd/core/config.cpp index 0604567..abcb779 100644 --- a/winixd/core/config.cpp +++ b/winixd/core/config.cpp @@ -4,8 +4,8 @@ * Author: Tomasz Sowa */ -/* - * Copyright (c) 2008-2022, Tomasz Sowa +/* + * Copyright (c) 2008-2026, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -180,10 +180,9 @@ void Config::AssignValues() image_quality = Int(L"image_quality", 92); convert_cmd = Text(L"convert_cmd", L"/usr/local/bin/convert"); - templates_dir = Text(L"templates_dir"); - templates_dir_default = Text(L"templates_dir_default"); - txt_templates_dir = Text(L"txt_templates_dir"); - txt_templates_dir_default = Text(L"txt_templates_dir_default"); + ListText(L"html_templates_dirs", html_templates_dirs); + ListText(L"txt_templates_dirs", txt_templates_dirs); + templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_"); templates_fun_postfix = Text(L"templates_fun_postfix", L".html"); templates_index = Text(L"templates_index", L"index.html"); @@ -523,6 +522,8 @@ bool Config::ListText(const std::wstring & name, std::vector & lis return space.to_list(name, list); } + + bool Config::HasValue(const wchar_t * name, const wchar_t * value) { return space.has_value(name, value); diff --git a/winixd/core/config.h b/winixd/core/config.h index 3bea054..bf14f42 100644 --- a/winixd/core/config.h +++ b/winixd/core/config.h @@ -4,8 +4,8 @@ * Author: Tomasz Sowa */ -/* - * Copyright (c) 2008-2022, Tomasz Sowa +/* + * Copyright (c) 2008-2026, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -186,11 +186,13 @@ public: // default: 3 size_t fcgi_cannot_create_request_delay; - std::wstring templates_dir; - std::wstring templates_dir_default; // html templates from winix + // html templates directories + // by default a file from the last directory is chosen + std::vector html_templates_dirs; - std::wstring txt_templates_dir; - std::wstring txt_templates_dir_default; // txt (notifications) templates from winix + // txt (notifications) templates directories + // by default a file from the last directory is chosen + std::vector txt_templates_dirs; // prefix and postfix for functions templates // default: diff --git a/winixd/notify/notify.cpp b/winixd/notify/notify.cpp index b12cacd..83bfa06 100644 --- a/winixd/notify/notify.cpp +++ b/winixd/notify/notify.cpp @@ -4,8 +4,8 @@ * Author: Tomasz Sowa */ -/* - * Copyright (c) 2008-2024, Tomasz Sowa +/* + * Copyright (c) 2008-2026, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -97,7 +97,7 @@ bool Notify::Init() if( !thread_manager->Add(¬ify_thread, L"notifications") ) return false; - patterns.SetDirectories(config->txt_templates_dir, config->txt_templates_dir_default); + patterns.SetDirectories(config->txt_templates_dirs); patterns.SetLocale(&TemplatesFunctions::locale); patterns.SetLocaleFilter(&TemplatesFunctions::locale_filter); diff --git a/winixd/templates/patterns.cpp b/winixd/templates/patterns.cpp index 1303a2f..6aceaa6 100644 --- a/winixd/templates/patterns.cpp +++ b/winixd/templates/patterns.cpp @@ -4,8 +4,8 @@ * Author: Tomasz Sowa */ -/* - * Copyright (c) 2011-2015, Tomasz Sowa +/* + * Copyright (c) 2011-2026, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -59,13 +59,16 @@ void Patterns::SetDeleteWhiteItems(bool del_white) } -void Patterns::SetDirectories(const std::wstring & tmpl_dir, const std::wstring & tmpl_dir_def) +void Patterns::SetDirectories(const std::vector & tmpl_dirs) { - templates_dir = tmpl_dir; - templates_dir_def = tmpl_dir_def; + templates_dirs = tmpl_dirs; } +void Patterns::ClearDirectories() +{ + templates_dirs.clear(); +} void Patterns::SetLocale(Locale * plocale) @@ -138,7 +141,7 @@ void Patterns::ReadPatterns(Template & templ) * pattern_parser.SetCommentary() is set beforehand */ pattern_parser.DeleteWhiteTextItems(del_white_items); - pattern_parser.Directory(templates_dir, templates_dir_def); + pattern_parser.SetDirectories(templates_dirs); pattern_parser.SetLogger(&log); if( ezc_blocks ) diff --git a/winixd/templates/patterns.h b/winixd/templates/patterns.h index bec50ef..f55c13f 100644 --- a/winixd/templates/patterns.h +++ b/winixd/templates/patterns.h @@ -4,8 +4,8 @@ * Author: Tomasz Sowa */ -/* - * Copyright (c) 2011-2018, Tomasz Sowa +/* + * Copyright (c) 2011-2026, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -53,7 +53,8 @@ public: Patterns(); void SetDeleteWhiteItems(bool del_white); - void SetDirectories(const std::wstring & tmpl_dir, const std::wstring & tmpl_dir_def); + void SetDirectories(const std::vector & tmpl_dirs); + void ClearDirectories(); /* setting locale and locale_filter @@ -151,7 +152,7 @@ public: private: bool del_white_items; - std::wstring templates_dir, templates_dir_def; + std::vector templates_dirs; Locale * locale; LocaleFilter * locale_filter; diff --git a/winixd/templates/templates.cpp b/winixd/templates/templates.cpp index cdb7f18..49e0585 100644 --- a/winixd/templates/templates.cpp +++ b/winixd/templates/templates.cpp @@ -868,7 +868,7 @@ void Templates::Init() { using namespace TemplatesFunctions; - patterns.SetDirectories(config->templates_dir, config->templates_dir_default); + patterns.SetDirectories(config->html_templates_dirs); pattern_cacher.SetWhenDelete(config->pattern_cacher_when_delete, config->pattern_cacher_how_many_delete); CreateFunctions(); // create functions first (functions will be cached by patterns) ReadTemplates();