--- lmtp2nntp.c 2001/12/11 11:53:11 1.99
+++ lmtp2nntp.c 2001/12/17 12:58:18 1.100
@@ -43,6 +43,7 @@
#include "argz.h"
#include "shpat_match.h"
#include "l2.h"
+#include "var.h"
#include "daemon.h"
/* library version check (compile-time) */
@@ -183,6 +184,75 @@
struct utsname uname;
} lmtp2nntp_t;
+static var_config_t ctx_lookup_cfg = {
+ '$', /* varinit */
+ '{', /* startdelim */
+ '}', /* enddelim */
+ '[', /* startindex */
+ ']', /* endindex */
+ '#', /* current_index */
+ '\\', /* escape */
+ "a-zA-Z0-9_.-" /* namechars */
+};
+
+static var_rc_t ctx_lookup(
+ void *_ctx,
+ const char *var_ptr, size_t var_len, int var_idx,
+ const char **val_ptr, size_t *val_len, size_t *val_size)
+{
+ lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
+ const char *name;
+ size_t len;
+ size_t n;
+ char *cp;
+ var_rc_t rc;
+
+ log2(ctx, DEBUG, "lookup variable \"%s\" (%d)",
+ var_ptr /* FIXME: NUL-termination? */, var_len);
+ rc = VAR_ERR_UNDEFINED_VARIABLE;
+ if (strncasecmp(var_ptr, "lmtp2nntp.version", var_len) == 0) {
+ }
+ else if (strncasecmp(var_ptr, "os.name", var_len) == 0) {
+ }
+ else if (strncasecmp(var_ptr, "os.version", var_len) == 0) {
+ }
+ else if (var_len > 8 && strncasecmp(var_ptr, "msg.hdr.", 8) == 0) {
+ name = var_ptr + 8;
+ len = strlen(name);
+ if (ctx == NULL)
+ return VAR_ERR_UNDEFINED_VARIABLE;
+ if (ctx->msg == NULL)
+ return VAR_ERR_UNDEFINED_VARIABLE;
+ if (ctx->msg->azHeaders == NULL)
+ return VAR_ERR_UNDEFINED_VARIABLE;
+ cp = NULL;
+ while ((cp = argz_next(ctx->msg->azHeaders, ctx->msg->asHeaders, cp)) != NULL) {
+ char *cpVar, *cpVal;
+ int nVar, nVal;
+ cpVar = cp;
+ nVar = strlen(cpVar);
+ if ((cp = argz_next(ctx->msg->azHeaders, ctx->msg->asHeaders, cp)) == NULL)
+ break;
+ cpVal = cp;
+ nVal = strlen(cpVal);
+ if (len == (nVar-1) && strncasecmp(cpVar, name, len) == 0 && cpVar[len] == ':') {
+ *val_ptr = cpVal;
+ *val_len = nVal;
+ *val_size = 0;
+ rc = VAR_OK;
+ }
+ }
+ }
+ if (rc == VAR_OK)
+ log4(ctx, DEBUG, "lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)",
+ var_ptr /* FIXME: NUL-termination? */, var_len, *val_ptr, *val_len);
+ else
+ log3(ctx, DEBUG, "lookup variable \"%s\" (%d) failed: %s",
+ var_ptr /* FIXME: NUL-termination? */, var_len, var_strerror(rc));
+ return rc;
+}
+
+
static void lmtp_gfs_ns(struct ns *);
static void lmtp_gfs_lhlo(lmtp2nntp_t *);
static void lmtp_gfs_rset(lmtp2nntp_t *);
@@ -2061,7 +2131,16 @@
if ((ctx->asHeaderValuePairs >= 1) && ((ctx->asHeaderValuePairs & 1) == 0)) {
cp = NULL;
while ((cp = argz_next(ctx->azHeaderValuePairs, ctx->asHeaderValuePairs, cp)) != NULL) {
- argz_add(&ctx->msg->azHeaders, &ctx->msg->asHeaders, cp);
+ var_rc_t var_rc;
+ char *res_ptr;
+ if ((var_rc = var_expand(cp, strlen(cp), &res_ptr, NULL,
+ ctx_lookup, ctx, &ctx_lookup_cfg, TRUE)) != VAR_OK) {
+ log2(ctx, ERROR, "expansion of '%s' failed: %s", cp, var_strerror(var_rc));
+ continue;
+ }
+ log1(ctx, DEBUG, "adding expanded header: \"%s\"", res_ptr);
+ argz_add(&ctx->msg->azHeaders, &ctx->msg->asHeaders, res_ptr);
+ free(res_ptr);
}
}
|