OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp_config.c versions 1.51 and 1.52
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.51 -> 1.52

--- lmtp2nntp_config.c   2002/02/20 15:42:26     1.51
+++ lmtp2nntp_config.c   2002/02/21 15:47:54     1.52
@@ -1140,6 +1140,10 @@
     hdC->prev = NULL;
     hdNew->next = hdC->next;
     hdC->next = NULL;
+    if (hdNew->prev != NULL)
+        hdNew->prev->next = hdNew;
+    if (hdNew->next != NULL)
+        hdNew->next->prev = hdNew;
     headerdestroy(hdC);
 }
 
@@ -1208,7 +1212,7 @@
     */
     var_rc_t rc;
 
-    log2(ctx, DEBUG, "lookup variable \"%s\" (%d)", var_ptr, var_len);
+    log2(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d)", var_ptr, var_len);
     rc = VAR_ERR_UNDEFINED_VARIABLE;
     if (strncasecmp(var_ptr, "test", var_len) == 0) {
     }
@@ -1219,9 +1223,59 @@
         rc = VAR_OK;
     }
     if (rc == VAR_OK)
-        log4(ctx, DEBUG, "lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);
+        log4(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);
     else
-        log3(ctx, DEBUG, "lookup variable \"%s\" (%d) failed: %s", var_ptr, var_len, var_strerror(rc));
+        log3(ctx, DEBUG, "ctx_lookup variable \"%s\" (%d) failed: %s", var_ptr, var_len, var_strerror(rc));
+    return rc;
+}
+
+struct regex_ctx_st; //FIXME go into a header!
+typedef struct regex_ctx_st regex_ctx_t;
+struct regex_ctx_st {
+    int            nMatch;
+    const char   **acpMatch;
+    l2_env_t      *l2_env;
+    l2_channel_t  *l2;
+};
+
+static var_config_t regex_lookup_cfg = {
+    '$',          /* varinit       */ 
+    '{',          /* startdelim    */ 
+    '}',          /* enddelim      */ 
+    '[',          /* startindex    */ //FIXME
+    ']',          /* endindex      */ //FIXME
+    '#',          /* current_index */ //FIXME
+    '\\',         /* escape        */ 
+    "0-9"         /* namechars     */ 
+};
+
+static var_rc_t regex_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)
+{
+    regex_ctx_t *ctx = (regex_ctx_t *)_ctx;
+    /*FIXME
+    const char *name;
+    size_t len;
+    char *cp;
+    */
+    var_rc_t rc;
+    int i;
+
+    log2(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d)", var_ptr, var_len);
+    rc = VAR_ERR_UNDEFINED_VARIABLE;
+    i = atoi(var_ptr); /* works w '}' but '\0' termination as well */
+    if (i <= ctx->nMatch) {
+        *val_ptr = ctx->acpMatch[i];
+        *val_len = strlen(ctx->acpMatch[i]);
+        *val_size = 0;
+        rc = VAR_OK;
+    }
+    if (rc == VAR_OK)
+        log4(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d) ok: result is \"%s\" (%d)", var_ptr, var_len, *val_ptr, *val_len);
+    else
+        log3(ctx, DEBUG, "rgx_lookup variable \"%s\" (%d) failed: %s", var_ptr, var_len, var_strerror(rc));
     return rc;
 }
 
@@ -1251,59 +1305,114 @@
     int         buf_size;
 #define OVECSIZE 30
     int         ovec[OVECSIZE];
-    int         i;
     const char **cpList;
     */
-    int         ovec[OVECSIZE];
-    int         iCheck;
+    regex_ctx_t *regex_ctx;
+    int            ovec[OVECSIZE];
 
     { //FIXME debug code block
         int i;
+        headerrule_t *hrD;
+        headerdata_t *hdD;
 
         log0(ctx, DEBUG, "FIXME trace ---------- headerrewrite() ----------");
-        for (hrI = ctx->option_firstheaderrule; hrI != NULL; hrI = hrI->next)
-            log1(ctx, DEBUG, "hrI->header=%s", hrI->header);
-        for (hdI = ctx->msg->hdFirst; hdI != NULL; hdI = hdI->next) {
-            if (hdI->ndata == 0)
-                log1(ctx, DEBUG, "hdI->name=%s, (NO DATA)", hdI->name);
-            if (hdI->ndata == 1)
-                log2(ctx, DEBUG, "hdI->name=%s, hdI->data.s=%s", hdI->name, hdI->data.s);
-            if (hdI->ndata > 1)
-                for (i = 0; i < hdI->ndata; i++)
-                    log3(ctx, DEBUG, "hdI->name=%s, hdI->data.m[%d]=%s", hdI->name, i, hdI->data.m[i]);
+        for (hrD = ctx->option_firstheaderrule; hrD != NULL; hrD = hrD->next)
+            log1(ctx, DEBUG, "hrD->header=%s", hrD->header);
+        for (hdD = ctx->msg->hdFirst; hdD != NULL; hdD = hdD->next) {
+            if (hdD->ndata == 0)
+                log1(ctx, DEBUG, "hdD->name=%s: (NO DATA)", hdD->name);
+            if (hdD->ndata == 1)
+                log2(ctx, DEBUG, "hdD->name:hdD->data.s    %s: %s", hdD->name, hdD->data.s);
+            if (hdD->ndata > 1)
+                for (i = 0; i < hdD->ndata; i++)
+                    log3(ctx, DEBUG, "hdD->name:hdD->data.m[%d] %s: %s", i, hdD->name, hdD->data.m[i]);
         }
     }
     
+    regex_ctx = (regex_ctx_t *)mallocex(sizeof(regex_ctx_t));
+    regex_ctx->nMatch = 0;
+    regex_ctx->acpMatch = NULL;
+    regex_ctx->l2_env = ctx->l2_env;
+    regex_ctx->l2 = ctx->l2;
     for (hrI = ctx->option_firstheaderrule; hrI != NULL; hrI = hrI->next) { /* for each rule */
         //log1(ctx, DEBUG, "FIXME trace loop hrI=%.8lx", hrI);
+        { //FIXME debug code block
+            int i;
+            headerrule_t *hrD;
+            headerdata_t *hdD;
+
+            log0(ctx, DEBUG, "FIXME trace ---------- headerrewrite() ---------- MIDDLE");
+            for (hrD = ctx->option_firstheaderrule; hrD != NULL; hrD = hrD->next)
+                log1(ctx, DEBUG, "hrD->header=%s", hrD->header);
+            for (hdD = ctx->msg->hdFirst; hdD != NULL; hdD = hdD->next) {
+                //log3(ctx, DEBUG, "hdD=%.8lx, hdD->name=%.8lx, hdD->data.s=%.8lx", (long)hdD, (long)&hdD->name, (long)&hdD->data.s);
+                if (hdD->ndata == 0)
+                    log1(ctx, DEBUG, "hdD->name=%s: (NO DATA)", hdD->name);
+                if (hdD->ndata == 1)
+                    log2(ctx, DEBUG, "hdD->name:hdD->data.s    %s: %s", hdD->name, hdD->data.s);
+                if (hdD->ndata > 1)
+                    for (i = 0; i < hdD->ndata; i++)
+                        log3(ctx, DEBUG, "hdD->name:hdD->data.m[%d] %s: %s", i, hdD->name, hdD->data.m[i]);
+            }
+        }
         if (hrI->regex != NULL) {
             log1(ctx, DEBUG, "rule has regex %s", hrI->regex);
             for (hdI = ctx->msg->hdFirst; hdI != NULL; hdI = hdI->next) { /* for each header */
                 //log2(ctx, DEBUG, "FIXME trace loop hdI=%.8lx, hI->name=\"%s\"", hdI, hdI->name);
-                if (hdI->name == NULL || strlen(hdI->name) == 0)
-                    continue; //FIXME header w/o name cannot happen normally
-                iCheck = pcre_exec(hrI->pcreRegex, hrI->pcreExtra, hdI->name, strlen(hdI->name), 0, 0, ovec, OVECSIZE);
-                log1(ctx, DEBUG, "FIXME trace iCheck=%d", iCheck);
-                if (iCheck >= 1) {
-                    log0(ctx, DEBUG, "regex matches");
+                if (hdI->name == NULL || strlen(hdI->name) == 0 || hdI->ndata == 0)
+                    continue;
+                regex_ctx->nMatch = pcre_exec(hrI->pcreRegex, hrI->pcreExtra, hdI->name, strlen(hdI->name), 0, 0, ovec, OVECSIZE);
+                if (regex_ctx->nMatch >= 1) {
+                    int i;
+                    char *cp;
+                    log1(ctx, DEBUG, "regex matches, %d references", regex_ctx->nMatch);
+                    pcre_get_substring_list(hdI->name, ovec, regex_ctx->nMatch, &regex_ctx->acpMatch);
+                    if (regex_ctx->acpMatch != NULL)
+                        for (i = 0; i < regex_ctx->nMatch; i++)
+                            log2(ctx, DEBUG, "regex reference[%d]=\'%s\'", i, regex_ctx->acpMatch[i] == NULL ? "(UNDEFINED)" : regex_ctx->acpMatch[i]);
                     hdNew = headercreate();
-                    hdNew->name = strdupex(hrI->header); //FIXME rename ->header to ->name
+                    /* expanding regex references into header name */
+                    {
+                        var_rc_t var_rc;
+                        char *res_ptr;
+                        log1(ctx, DEBUG, "expanding regex references in headername '%s'", hrI->header);
+                        if ((var_rc = var_expand(hrI->header, strlen(hrI->header), &res_ptr, NULL,
+                                                 regex_lookup, regex_ctx, &regex_lookup_cfg, TRUE)) != VAR_OK) {
+                            log2(ctx, ERROR, "expansion of '%s' failed: %s", hrI->header, var_strerror(var_rc));
+                        }
+                        log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
+                        hdNew->name = res_ptr; //FIXME rename ->header to ->name
+                    }
+                    /* expanding regex references into header value */
+                    {
+                        var_rc_t var_rc;
+                        char *res_ptr;
+                        log1(ctx, DEBUG, "expanding regex references in header value '%s'", hrI->val);
+                        if ((var_rc = var_expand(hrI->val, strlen(hrI->val), &res_ptr, NULL,
+                                                 regex_lookup, regex_ctx, &regex_lookup_cfg, TRUE)) != VAR_OK) {
+                            log2(ctx, ERROR, "expansion of '%s' failed: %s", hrI->val, var_strerror(var_rc));
+                        }
+                        log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
+                        cp = res_ptr;
+                    }
+                    /* expanding header and other variables into header value */
                     {
-                    var_rc_t var_rc;
-                    char *res_ptr;
-                    if ((var_rc = var_expand(hrI->val, strlen(hrI->val), &res_ptr, NULL,
-                                             ctx_lookup, ctx, &ctx_lookup_cfg, TRUE)) != VAR_OK) {
-                        log2(ctx, ERROR, "expansion of '%s' failed: %s", hrI->val, var_strerror(var_rc));
+                        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, TRUE)) != VAR_OK) {
+                            log2(ctx, ERROR, "expansion of '%s' failed: %s", cp, var_strerror(var_rc));
+                        }
+                        log1(ctx, DEBUG, "expansion result '%s'", res_ptr);
+                        hdNew->data.s = res_ptr;
+                        hdNew->ndata = 1;
                     }
-                    log2(ctx, ERROR, "expansion of '%s' succeeded: %s", hrI->val, res_ptr);
-                    hdNew->data.s = res_ptr;
-                    hdNew->ndata = 1;
                     /*FIXME clean up data.m */
                     headerreplace(hdI, hdNew);
                     if (hdNew->prev == NULL)
                         ctx->msg->hdFirst = hdNew;
                     hdI = hdNew;
-                    }
                 }
             }
         }
@@ -1311,9 +1420,16 @@
             log1(ctx, DEBUG, "rule has no regex but static header %s", hrI->header);
             hdNew = headercreate();
             hdNew->name = strdupex(hrI->header); //FIXME rename ->header to ->name
-            hdNew->data.s = strdupex(hrI->val);
-            hdNew->ndata = 1;
-            /*FIXME clean up data.m */
+            if (hrI->val == NULL) {
+                log0(ctx, DEBUG, "marking deleted");
+                /*FIXME clean up data.s and data.m */
+                hdNew->ndata = 0;
+            }
+            else {
+                hdNew->data.s = strdupex(hrI->val);
+                hdNew->ndata = 1;
+                /*FIXME clean up data.m */
+            }
             for (hdI = ctx->msg->hdFirst; hdI != NULL; hdI = hdI->next) { /* for each header */
                 if (hdI->name == NULL || strlen(hdI->name) == 0)
                     continue; //FIXME header w/o name cannot happen normally
@@ -1323,9 +1439,17 @@
             }
             if (hdI != NULL) {
                 log1(ctx, DEBUG, "replacing header %s", hrI->header);
+                log3(ctx, DEBUG, "ctx->msg->hdFirst=%.8lx, hdI      =%.8lx, hdNew      =%.8lx", ctx->msg->hdFirst, hdI, hdNew);
+                log2(ctx, DEBUG, "                            hdI->prev=%.8lx, hdNew->prev=%.8lx", hdI->prev, hdNew->prev);
+                log2(ctx, DEBUG, "                            hdI->next=%.8lx, hdNew->next=%.8lx", hdI->next, hdNew->next);
                 headerreplace(hdI, hdNew);
-                if (hdNew->prev == NULL)
+                log3(ctx, DEBUG, "ctx->msg->hdFirst=%.8lx, hdI      =%.8lx, hdNew      =%.8lx", ctx->msg->hdFirst, hdI, hdNew);
+                log2(ctx, DEBUG, "                            hdI->prev=%.8lx, hdNew->prev=%.8lx", hdI->prev, hdNew->prev);
+                log2(ctx, DEBUG, "                            hdI->next=%.8lx, hdNew->next=%.8lx", hdI->next, hdNew->next);
+                if (hdNew->prev == NULL) {
+                    log0(ctx, DEBUG, "FIXME trace #1");
                     ctx->msg->hdFirst = hdNew;
+                }
             }
             else {
                 log1(ctx, DEBUG, "appending header %s", hrI->header);
@@ -1338,18 +1462,20 @@
 
     { //FIXME debug code block
         int i;
+        headerrule_t *hrD;
+        headerdata_t *hdD;
 
         log0(ctx, DEBUG, "FIXME trace ---------- headerrewrite() ---------- FINISH");
-        for (hrI = ctx->option_firstheaderrule; hrI != NULL; hrI = hrI->next)
-            log1(ctx, DEBUG, "hrI->header=%s", hrI->header);
-        for (hdI = ctx->msg->hdFirst; hdI != NULL; hdI = hdI->next) {
-            if (hdI->ndata == 0)
-                log1(ctx, DEBUG, "hdI->name=%s, (NO DATA)", hdI->name);
-            if (hdI->ndata == 1)
-                log2(ctx, DEBUG, "hdI->name=%s, hdI->data.s=%s", hdI->name, hdI->data.s);
-            if (hdI->ndata > 1)
-                for (i = 0; i < hdI->ndata; i++)
-                    log3(ctx, DEBUG, "hdI->name=%s, hdI->data.m[%d]=%s", hdI->name, i, hdI->data.m[i]);
+        for (hrD = ctx->option_firstheaderrule; hrD != NULL; hrD = hrD->next)
+            log1(ctx, DEBUG, "hrD->header=%s", hrD->header);
+        for (hdD = ctx->msg->hdFirst; hdD != NULL; hdD = hdD->next) {
+            if (hdD->ndata == 0)
+                log1(ctx, DEBUG, "hdD->name=%s: (NO DATA)", hdD->name);
+            if (hdD->ndata == 1)
+                log2(ctx, DEBUG, "hdD->name:hdD->data.s    %s: %s", hdD->name, hdD->data.s);
+            if (hdD->ndata > 1)
+                for (i = 0; i < hdD->ndata; i++)
+                    log3(ctx, DEBUG, "hdD->name:hdD->data.m[%d] %s: %s", i, hdD->name, hdD->data.m[i]);
         }
     }
 }
@@ -1368,6 +1494,7 @@
     hdNew->data.s = "foo@invalid.com";
     hdNew->ndata = 1;
     ctx->msg->hdFirst = hdNew;
+    hdNew->prev = NULL;
     hdI = hdNew;
 
     hdNew = headercreate();
@@ -1375,6 +1502,7 @@
     hdNew->data.m = replyto;
     hdNew->ndata = 3;
     hdI->next = hdNew;
+    hdNew->prev = hdI;
     hdI = hdNew;
 
     hdNew = headercreate();
@@ -1382,6 +1510,7 @@
     hdNew->data.s = "a tiny little test";
     hdNew->ndata = 1;
     hdI->next = hdNew;
+    hdNew->prev = hdI;
     hdI = hdNew;
 
     hdNew = headercreate();
@@ -1389,6 +1518,7 @@
     hdNew->data.s = "Mon, 18 Feb 2002 09:43:52 +0100";
     hdNew->ndata = 1;
     hdI->next = hdNew;
+    hdNew->prev = hdI;
     hdI = hdNew;
 
     hdNew = headercreate();
@@ -1396,7 +1526,9 @@
     hdNew->data.s = "<200201172300.AAA29400@procter012.pg-cw.de>";
     hdNew->ndata = 1;
     hdI->next = hdNew;
+    hdNew->prev = hdI;
     hdI = hdNew;
 
+    hdI->next = NULL;
     headerrewrite(ctx);
 }

CVSTrac 2.0.1