template thingy polish/fix;

This commit is contained in:
Alexander Vdolainen 2026-10-14 22:31:42 +03:00
parent 685b87d5e1
commit 4ebd9abd8c
2 changed files with 46 additions and 4 deletions

View File

@ -1,12 +1,31 @@
/* template.h - Template parser and string variable substitution engine */
/*
* this is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* this is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
* (c) Alexander Vdolainen 2007, 2026 <alex@vapaa.xyz>
* subrelay: a minimalistic maillist server based on external IMAPs/SMTPs
*
* template.h: expand templates
*
*/
#ifndef __TEMPLATE_H__
#define __TEMPLATE_H__
#include <stddef.h>
typedef struct template_var {
const char *key; /* e.g., "MAILLIST_NAME" (without the '$') */
const char *val; /* e.g., "Civilisation List" */
const char *key;
const char *val;
} template_var_t;
/*

View File

@ -1,4 +1,24 @@
/* template.c - Template substitution implementation */
/*
* this is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* this is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
* (c) Alexander Vdolainen 2007, 2026 <alex@vapaa.xyz>
* subrelay: a minimalistic maillist server based on external IMAPs/SMTPs
*
* template.c: expand templates
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -23,6 +43,9 @@ char *template_render_string(const char *src, const template_var_t *vars, size_t
char *out = malloc(buf_cap);
if (!out) return NULL;
if (!src || (var_count > 0 && !vars))
return NULL;
const char *p = src;
while (*p) {