OSSP CVS Repository

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

Check-in Number: 1845
Date: 2002-Feb-13 17:25:38 (local)
2002-Feb-13 16:25:38 (UTC)
User:thl
Branch:
Comment: new -h option and config
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/00TODO      1.54 -> 1.55     1 inserted, 1 deleted
ossp-pkg/lmtp2nntp/fixme.h      1.13 -> 1.14     16 inserted, 0 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.47 -> 1.48     50 inserted, 17 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_main.c      1.39 -> 1.40     16 inserted, 2 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_option.c      1.13 -> 1.14     1 inserted, 1 deleted

ossp-pkg/lmtp2nntp/00TODO 1.54 -> 1.55

--- 00TODO       2002/02/13 13:46:58     1.54
+++ 00TODO       2002/02/13 16:25:38     1.55
@@ -99,7 +99,7 @@
 
   create an array with columns for "header" and every value, index is "header";
 
-  -h [priority]:[regex]:header:[value]
+  -h [pri]:[regex]:header:[val]
 
   # merge values from duplicate headers and separte them with "comma space"
   -h :(Reply-To|To|Cc|Bcc):$0: [%{$0[#]}%{$0[#+1]:+, }]


ossp-pkg/lmtp2nntp/fixme.h 1.13 -> 1.14

--- fixme.h      2002/02/07 08:59:44     1.13
+++ fixme.h      2002/02/13 16:25:38     1.14
@@ -29,6 +29,17 @@
     char   *lhlo_domain;
 };
 #include <sys/utsname.h>
+
+struct headerrule_st;
+typedef struct headerrule_st headerrule_t;
+struct headerrule_st {
+    headerrule_t *next;
+    int           pri;
+    char         *regex;
+    char         *header;
+    char         *val;
+};
+
 typedef struct {
     l2_context_t    ctx;
     val_t          *val;
@@ -38,8 +49,13 @@
     char           *option_operationmodefakestatus;
     char           *option_operationmodefakedsn;
     int             option_maxmessagesize;
+
+    headerrule_t   *option_firstheaderrule;
+    /* FIXME obsolete */
     char           *azHeaderValuePairs;
     size_t          asHeaderValuePairs;
+
+
     int             option_timeout_lmtp_accept;
     int             option_timeout_lmtp_read;
     int             option_timeout_lmtp_write;


ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.47 -> 1.48

--- lmtp2nntp_config.c   2002/02/07 13:36:16     1.47
+++ lmtp2nntp_config.c   2002/02/13 16:25:38     1.48
@@ -526,45 +526,78 @@
     catch (ex)
         rethrow;
 
-    /* --headervalue MULTI */
+    /* --headerrule MULTI */
     try {
         char *cp;
         int i;
+        char *cpPri;
+        char *cpRegex;
         char *cpHeader;
-        char *cpValue;
+        char *cpVal;
+        headerrule_t *hrNew;
+        headerrule_t *hrI;
+        headerrule_t *hrP;
 
-        if (   (val_get(ctx->val, "option.headervalue", &ov) != VAL_OK)
+        if (   (val_get(ctx->val, "option.headerrule", &ov) != VAL_OK)
             || (ov->ndata <  0)
             || (ov->ndata >= 1 && ov->data.m == NULL)
               ) throw(0,0,0);
         log1(ctx, DEBUG, "ov->ndata = %d", ov->ndata);
         for (i = 0; i < ov->ndata; i++)
-            log2(ctx, TRACE, "--headervalue[%d] = \"%s\"", i, (ov->data.m)[i]);
+            log2(ctx, TRACE, "--headerule[%d] = \"%s\"", i, (ov->data.m)[i]);
 
         if (ov->ndata >= 1) {
             for (i = 0; i < ov->ndata; i++) {
                 cp = (ov->data.m)[i];
                 log2(ctx, DEBUG, "cp = (data.m)[%d] = \"%s\"", i, cp);
-                cpHeader = strdup(cp);
-                if ((cp = strchr(cpHeader, ':')) == NULL) {
-                    log1(ctx, ERROR, "option --headervalue, header (%s) terminating colon missing", (ov->data.m)[i]);
+                cp = strdup(cp); //FIXME
+                /* priority */
+                cpPri = cp;
+                if ((cp = strchr(cp, ':')) == NULL) {
+                    log1(ctx, ERROR, "option --headerrule, priority (%s) terminating colon missing", (ov->data.m)[i]);
                     throw(0,0,0);
                 }
+                *cp = NUL;
                 cp++;
+                /* regex */
+                cpRegex = cp;
+                if ((cp = strchr(cp, ':')) == NULL) {
+                    log1(ctx, ERROR, "option --headerrule, regex (%s) terminating colon missing", (ov->data.m)[i]);
+                    throw(0,0,0);
+                }
                 *cp = NUL;
-                log2(ctx, DEBUG, "header[%d] = \"%s\"", i, cpHeader);
                 cp++;
-                while (*cp == ' ') cp++; //FIXME note this in NEWS
-                if (*cp == NUL) {
-                    log1(ctx, ERROR, "option --headervalue, value (%s) missing", (ov->data.m)[i]);
+                /* header */
+                cpHeader = cp;
+                if ((cp = strchr(cp, ':')) == NULL) {
+                    log1(ctx, ERROR, "option --headerrule, header (%s) terminating colon missing", (ov->data.m)[i]);
                     throw(0,0,0);
                 }
-                cpValue = strdup(cp);
-                log2(ctx, DEBUG, " value[%d] = \"%s\"", i, cpValue);
-                argz_add(&ctx->azHeaderValuePairs, &ctx->asHeaderValuePairs, cpHeader);
-                argz_add(&ctx->azHeaderValuePairs, &ctx->asHeaderValuePairs, cpValue);
-                free(cpHeader);
-                free(cpValue);
+                *cp = NUL;
+                cp++;
+                /* value */
+                cpVal = cp;
+
+                if ((hrNew = (headerrule_t *)malloc(sizeof(headerrule_t))) == NULL) throw(0,0,0);
+                hrNew->next   = NULL;
+                hrNew->pri    = atoi(cpPri);
+                hrNew->regex  = cpRegex;
+                hrNew->header = cpHeader;
+                hrNew->val    = cpVal;
+
+                if (ctx->option_firstheaderrule == NULL)
+                    ctx->option_firstheaderrule = hrNew;
+                else {
+                    for (hrP = NULL, hrI = ctx->option_firstheaderrule;
+                         hrI != NULL && hrI->pri <= hrNew->pri;
+                         hrP = hrI, hrI = hrI->next);
+                    if (hrI != NULL)
+                        hrNew->next = hrI; /* insert */
+                    if (hrP != NULL)
+                        hrP->next = hrNew; /* append */
+                    else
+                        ctx->option_firstheaderrule = hrNew; /* newfirst */
+                }
             }
         }
     }


ossp-pkg/lmtp2nntp/lmtp2nntp_main.c 1.39 -> 1.40

--- lmtp2nntp_main.c     2002/02/07 13:38:08     1.39
+++ lmtp2nntp_main.c     2002/02/13 16:25:38     1.40
@@ -349,8 +349,9 @@
     ctx->option_operationmodefakestatus = NULL;
     ctx->option_operationmodefakedsn    = NULL;
     ctx->option_maxmessagesize = 0;
-    ctx->azHeaderValuePairs = NULL;
-    ctx->asHeaderValuePairs = 0;
+    ctx->option_firstheaderrule = NULL;
+    ctx->azHeaderValuePairs = NULL; //FIXME obsolete
+    ctx->asHeaderValuePairs = 0;    //FIXME obsolete
     ctx->option_timeout_lmtp_accept  = 0;
     ctx->option_timeout_lmtp_read    = 0;
     ctx->option_timeout_lmtp_write   = 0;
@@ -399,6 +400,19 @@
     (void)option_parse(o, argc, argv);
     (void)config_context(ctx);
 
+{
+headerrule_t *hrI;
+fprintf(stderr, "DEBUG: los geht's\n");
+for (hrI = ctx->option_firstheaderrule; hrI != NULL; hrI = hrI->next) {
+    fprintf(stderr, "DEBUG: cpPri    = %d\n", hrI->pri);
+    fprintf(stderr, "DEBUG: cpRegex  = \"%s\"\n", hrI->regex);
+    fprintf(stderr, "DEBUG: cpHeader = \"%s\"\n", hrI->header);
+    fprintf(stderr, "DEBUG: cpValue  = \"%s\"\n", hrI->val);
+}
+fprintf(stderr, "DEBUG: das war's\n");
+}
+    CU(0); //FIXME
+
     if (getuid() != ctx->option_uid) {
         if (setuid(ctx->option_uid) == -1) {
             fprintf(stderr, "%s:Error: Setting UID to %d failed: %s\n", 


ossp-pkg/lmtp2nntp/lmtp2nntp_option.c 1.13 -> 1.14

--- lmtp2nntp_option.c   2002/02/06 13:51:38     1.13
+++ lmtp2nntp_option.c   2002/02/13 16:25:38     1.14
@@ -616,7 +616,7 @@
     (void)option_register(o, "client",             'c', OPT_SINGLE,  NULL,        "NNTP client bind",                  "addr[:port]",                &stdsyntax, "m/.*/" );
     (void)option_register(o, "destination",        'd', OPT_MULTI,   NULL,        "NNTP client destination",           "addr[:port]",                &stdsyntax, "m/.*/" );
     (void)option_register(o, "groupmode",          'g', OPT_SINGLE,  "arg",       "arg|envelope|header",               "groupmode",                  &stdsyntax, "m/.*/" ); //"m/(arg|envelope|header)/" );
-    (void)option_register(o, "headervalue",        'h', OPT_MULTI,   NULL,        "header/ value added to message",    "header: value",              &stdsyntax, "m/.*/" );
+    (void)option_register(o, "headerrule",         'h', OPT_MULTI,   NULL,        "header rewriting rule",             "[pri]:[regex]:header:[val]", &stdsyntax, "m/^[0-9]*:.*:.+:.*$/" );
     (void)option_register(o, "include",            'i', OPT_MULTI,   NULL,        "configfile to include",             "configfile",                 &includeit, "m/.*/" );
     (void)option_register(o, "timeoutlmtp",        NUL, OPT_SINGLE,  NULL,        "LMTP server default timeout",       "sec",                        &stdsyntax, "m/.*/" );
     (void)option_register(o, "timeoutlmtpaccept",  NUL, OPT_SINGLE,  "0",         "LMTP server accept timeout",        "sec",                        &stdsyntax, "m/.*/" );

CVSTrac 2.0.1