template thingy polish/fix;
This commit is contained in:
parent
685b87d5e1
commit
4ebd9abd8c
@ -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;
|
||||
|
||||
/*
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user