OSSP CVS Repository

ossp - Check-in [1920]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1920
Date: 2002-Feb-28 15:02:25 (local)
2002-Feb-28 14:02:25 (UTC)
User:thl
Branch:
Comment: var callback now supports message header lookups
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.59 -> 1.60     11 inserted, 6 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_main.c      1.42 -> 1.43     33 inserted, 5 deleted

ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.59 -> 1.60

--- lmtp2nntp_config.c   2002/02/28 12:57:55     1.59
+++ lmtp2nntp_config.c   2002/02/28 14:02:25     1.60
@@ -1619,10 +1619,6 @@
                             var_rc_t var_rc;
                             char *res_ptr;
                             log1(ctx, DEBUG, "expanding variables in header value '%s'", hrI->val);
-                            var_rc_t var_expand(var_t *var, const char *src_ptr,
-                                   size_t src_len, char **dst_ptr, size_t *dst_len, int
-                                          force_expand);
-                            
                             //if ((var_rc = var_expand(cp, strlen(cp), &res_ptr, NULL, ctx_lookup, ctx, &ctx_lookup_cfg, FALSE)) != VAR_OK) {
                             if ((var_rc = var_expand(ctx->config_varctx, cp, strlen(cp), &res_ptr, NULL, FALSE)) != VAR_OK) {
                                 log3(ctx, ERROR, "expansion of '%s' failed: %s", cp, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
@@ -1650,9 +1646,18 @@
                 hdNew->ndata = 0;
             }
             else {
-                hdNew->data.s = strdupex(hrI->val);
-                hdNew->ndata = 1;
                 /*FIXME clean up data.m */
+                /* expanding header and other variables into header value */
+                var_rc_t var_rc;
+                char *res_ptr;
+                log1(ctx, DEBUG, "expanding variables in header value '%s'", hrI->val);
+                //if ((var_rc = var_expand(cp, strlen(cp), &res_ptr, NULL, ctx_lookup, ctx, &ctx_lookup_cfg, FALSE)) != VAR_OK) {
+                if ((var_rc = var_expand(ctx->config_varctx, hrI->val, strlen(hrI->val), &res_ptr, NULL, FALSE)) != VAR_OK) {
+                    log3(ctx, ERROR, "expansion of '%s' failed: %s", hrI->val, var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
+                }
+                log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
+                hdNew->data.s = res_ptr;
+                hdNew->ndata = 1;
             }
             for (hdI = ctx->msg->hdFirst; hdI != NULL; hdI = hdI->next) { /* for each header */
                 if (hdI->name == NULL || strlen(hdI->name) == 0)


ossp-pkg/lmtp2nntp/lmtp2nntp_main.c 1.42 -> 1.43

--- lmtp2nntp_main.c     2002/02/28 12:57:55     1.42
+++ lmtp2nntp_main.c     2002/02/28 14:02:26     1.43
@@ -222,11 +222,39 @@
         }
         free(cp);
     }
-    else if (strncasecmp(var_ptr, "xyz", var_len) == 0) {
-        *val_ptr = "Hello, World!";
-        *val_len = strlen("Hello, World!");
-        *val_size = 0;
-        rc = VAR_OK;
+    else if (   (strncasecmp(var_ptr, "msg.header.", strlen("msg.header.")) == 0)
+             && (ctx->msg != NULL)
+               ) {
+        headerdata_t *hdI;
+        int n;
+        cp = str_dupex(var_ptr + strlen("msg.header."), var_len - strlen("msg.header.") + 1);
+        n = strlen(cp);
+        cp[n]= ':';
+        cp[n + 1] = NUL;
+        log2(ctx, DEBUG, "FIXME var_idx=%d, cp=%s", var_idx, cp);
+        for (hdI = ctx->msg->hdFirst; hdI != NULL; hdI = hdI->next) { /* for each header */
+            log1(ctx, DEBUG, "FIXME hdI->name=%s", hdI->name);
+            if (hdI->name == NULL || strlen(hdI->name) == 0)
+                continue; //FIXME header w/o name cannot happen normally
+            if (strcmp(cp, hdI->name) == 0)
+                break;
+        }
+        if (hdI != NULL) {
+            log1(ctx, DEBUG, "FIXME hdI->ndata=%d", hdI->ndata);
+            if ((var_idx == 0) && (hdI->ndata == 1)) { /* request first/only single value */
+                *val_ptr = hdI->data.s;
+                *val_len = strlen(hdI->data.s);
+                *val_size = 0;
+                rc = VAR_OK;
+            }
+            else if (var_idx < hdI->ndata) { /* request from multi value */
+                *val_ptr = hdI->data.m[var_idx];
+                *val_len = strlen(hdI->data.m[var_idx]);
+                *val_size = 0;
+                rc = VAR_OK;
+            }
+        }
+        free(cp);
     }
     if (rc == VAR_OK)
         log4(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);

CVSTrac 2.0.1