OSSP CVS Repository

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

Check-in Number: 1898
Date: 2002-Feb-26 16:56:08 (local)
2002-Feb-26 15:56:08 (UTC)
User:thl
Branch:
Comment: added --testfile option for header rewrite testing. Transformation from argz to linked list of elements and back implemented for integration into the gateway's "inner loop". Have trouble with lib_ex segfaulting when throwing exception and tried to track down this issue with no luck.
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.52 -> 1.53     267 inserted, 26 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_msg.c      1.2 -> 1.3     1 inserted, 0 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_option.c      1.14 -> 1.15     1 inserted, 0 deleted

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

--- lmtp2nntp_config.c   2002/02/21 15:47:54     1.52
+++ lmtp2nntp_config.c   2002/02/26 15:56:08     1.53
@@ -105,7 +105,28 @@
 }
 
 static void headersimulation(lmtp2nntp_t *); //FIXME
+static void msg_headermatrixbuildup(msg_t *msg);
+static void msg_headermatrixteardwn(msg_t *msg);
+static void headerrewrite(lmtp2nntp_t *ctx);
 
+static void extest(void)
+{
+    ex_t ex;
+
+    try {
+        fprintf(stderr, "try\n");
+        throw(0,0,0);
+    }
+    cleanup {
+        fprintf(stderr, "cleanup\n");
+    }
+    catch (ex) {
+        fprintf(stderr, "catch\n");
+        rethrow;
+    }
+    exit(0);
+
+}
 void config_context(lmtp2nntp_t *ctx)
 {
     ex_t ex;
@@ -113,6 +134,8 @@
     //char *cp;
     int rc;
 
+    //FIXME ex is broken!?  extest();
+
     /* create L2 environment */
     if (l2_env_create(&ctx->l2_env) != L2_OK) {
         fprintf(stderr, "%s:Error: failed to create L2 environment\n", ctx->progname);
@@ -1021,8 +1044,107 @@
     catch (ex)
         rethrow;
 
-    headersimulation(ctx); //FIXME
+    //headersimulation(ctx); //FIXME
+    /* --testfile MULTI */
+    try {
+        char *cp;
+        int i;
+        char *cpBuf = NULL;
+
+        if (   (val_get(ctx->val, "option.testfile", &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, "--testfile[%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);
+                {
+                    const char *filename = cp;
+                    struct stat sb;
+                    volatile int fd = -1;
+                    //ex_t ex;
+
+                    try {
+                        if (stat(filename, &sb) == -1) throw(0, 0, "stat");
+                        if ((cpBuf = (char *)malloc((size_t)sb.st_size + 1)) == NULL) throw(0, 0, "malloc");
+                        if ((fd = open(filename, O_RDONLY)) == -1) throw(0, 0, "open");
+                        if (read(fd, (void *)cpBuf, (size_t)sb.st_size) != (ssize_t)sb.st_size) throw(0, 0, "read");
+                        cpBuf[(int)sb.st_size] = '\0';
+                    }
+                    cleanup {
+                        if (fd != -1) close(fd);
+                    }
+                    catch (ex) {
+                        fprintf(stderr, "ERROR: caught %s\n", ex.ex_value == NULL ? "N/A" : (char *)ex.ex_value);
+                        rethrow;
+                    }
+                }
+                //printf("DEBUG: *** 1 *** file as it was just read in ***\n%s***\n", cpBuf);
+                {
+                    volatile msg_t *msg = NULL;
+                    msg_rc_t rc;
+
+                    try {
+                        if ((msg = msg_create()) == NULL) throw(0, 0, "msg_create");
+                        msg->l2 = ctx->l2;
+                        msg->cpMsg = cpBuf;
+                        if ((rc = msg_split((msg_t *)msg)) != MSG_OK) {
+                            log1(ctx, ERROR, "Error splitting message: %s", msg_error(rc));
+                            throw(0, 0, "msg_split");
+                        }
+                        {//FIXME
+                            char *cp;
+                            cp = NULL;
+                            log0(msg, DEBUG, "FIXME trace #20");
+                            while ((cp = argz_next(msg->azHeaders, msg->asHeaders, cp)) != NULL) {
+                                log1(msg, DEBUG, "header=\"%s\"", cp);
+                            }
+                            log0(msg, DEBUG, "FIXME trace #21");
+                        }
+                        msg_headermatrixbuildup((msg_t *)msg);
+                        ctx->msg = (msg_t *)msg;
+                        headerrewrite(ctx);
+                        msg_headermatrixteardwn((msg_t *)msg);
+                        {//FIXME
+                            char *cp;
+                            cp = NULL;
+                            log0(msg, DEBUG, "FIXME trace #30");
+                            while ((cp = argz_next(msg->azHeaders, msg->asHeaders, cp)) != NULL) {
+                                log1(msg, DEBUG, "header=\"%s\"", cp);
+                            }
+                            log0(msg, DEBUG, "FIXME trace #31");
+                        }
+                        argz_add(&((msg_t *)msg)->azNewsgroups, &((msg_t *)msg)->asNewsgroups, "Newsgroups:"); //FIXME
+                        argz_add(&((msg_t *)msg)->azNewsgroups, &((msg_t *)msg)->asNewsgroups, "invalid.tst"); //FIXME
+                        if ((rc = msg_join((msg_t *)msg)) != MSG_OK) {
+                            log1(ctx, ERROR, "Error joining message: %s", msg_error(rc));
+                            throw(0, 0, "msg_split");
+                        }
+                        printf("%s", msg->cpMsg); //FIXME
+                    }
+                    cleanup {
+                        if (msg != NULL)
+                            msg_destroy((msg_t *)msg);
+                        ctx->msg = NULL;
+                    }
+                    catch (ex) {
+                        rethrow;
+                    }
+                }
+            }
+        exit(0); //FIXME
+        }
+    }
+    catch (ex)
+        rethrow;
+
 
+#if 0
 //void testpcre(void)
 {
     char       *szRegex;
@@ -1092,6 +1214,7 @@
         free(pcreExtra);
 
 }
+#endif
 
 CUS:
     return;
@@ -1166,26 +1289,6 @@
     return (headerdata_t *)hdNew;
 }
 #if 0
-//headermatrix()
-{
-    volatile header_t *hNew = NULL;
-    try {
-        char *cp;
-
-        cp = NULL;
-        while ((cp = argz_next(ctx->msg->azHeaders, ctx->msg->asHeaders, cp)) != NULL) {
-            hNew = mallocex(sizeof(header_t));
-            //FIXME
-        }
-    }
-    cleanup {
-        if (hNew != NULL)
-            free(hNew);
-    }
-    catch(ex) {
-        rethrow;
-    }
-}
 #endif
 
 static var_config_t ctx_lookup_cfg = {
@@ -1265,7 +1368,7 @@
 
     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 */
+    i = atoi(var_ptr); /* works with both '}' and '\0' termination */
     if (i <= ctx->nMatch) {
         *val_ptr = ctx->acpMatch[i];
         *val_len = strlen(ctx->acpMatch[i]);
@@ -1279,6 +1382,144 @@
     return rc;
 }
 
+static void msg_headermatrixbuildup(msg_t *msg)
+{
+    ex_t ex;
+    volatile headerdata_t *hdNew = NULL;
+    try {
+        headerdata_t *hdI, *hdP;
+        char *cp;
+
+        cp = NULL;
+        while ((cp = argz_next(msg->azHeaders, msg->asHeaders, cp)) != NULL) { /* for each message header */
+            log2(msg, DEBUG, "FIXME trace loop cp=%.8lx, cp=\"%s\"", cp, cp);
+
+            /*FIXME we want O(1) here */
+            for (hdP = NULL, hdI = msg->hdFirst; hdI != NULL; hdP = hdI, hdI = hdI->next) { /* for each matrix header */
+                log2(msg, DEBUG, "FIXME trace loop hdI=%.8lx, hI->name=\"%s\"", hdI, hdI->name);
+                if (hdI->name == NULL || strlen(hdI->name) == 0 || hdI->ndata == 0)
+                    continue;
+                if (strcmp(cp, hdI->name) == 0)
+                    break;
+            }
+
+            if (hdI == NULL) {
+                hdNew = headercreate(); /* not found, create new */
+                hdNew->name = strdupex(cp);
+                hdI = (headerdata_t *)hdNew; hdNew = NULL; /* ex cleanup */
+                if (hdP == NULL)
+                    msg->hdFirst = hdI; /* no previous? this is the first */
+                else {
+                    hdP->next = hdI;
+                    hdI->prev = hdP;
+                }
+            }
+            cp = argz_next(msg->azHeaders, msg->asHeaders, cp);
+            if (hdI->ndata == 0) {
+                log1(msg, DEBUG, "header=%s, currently empty", hdI->name);
+                hdI->data.s = strdupex(cp);
+                hdI->ndata = 1;
+            }
+            else if(hdI->ndata == 1) {
+                char *cpOld;
+                cpOld = hdI->data.s;
+                log1(msg, DEBUG, "header=%s, currently single valued", hdI->name);
+                hdI->data.m = (char **)mallocex(3 * sizeof(char *));
+                hdI->data.m[0] = strdupex(cpOld); //FIXME
+                hdI->data.m[1] = strdupex(cp);
+                hdI->data.m[2] = NULL;
+                hdI->ndata = 2;
+            }
+            else {
+                log2(msg, DEBUG, "header=%s, currently multi valued %d", hdI->name, hdI->ndata);
+                hdI->data.m = (char **)reallocex(hdI->data.m, (hdI->ndata + 2) * sizeof(char *));
+                hdI->data.m[hdI->ndata++] = strdupex(cp);
+                hdI->data.m[hdI->ndata] = NULL;
+            }
+        }
+#if 0
+        { //FIXME debug code block
+            int i;
+            headerdata_t *hdD;
+
+            log0(msg, DEBUG, "FIXME trace ---------- msg_headermatrixbuildup() ----------");
+            for (hdD = msg->hdFirst; hdD != NULL; hdD = hdD->next) {
+                if (hdD->ndata == 0)
+                    log1(msg, DEBUG, "hdD->name=%s: (NO DATA)", hdD->name);
+                if (hdD->ndata == 1)
+                    log2(msg, 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(msg, DEBUG, "hdD->name:hdD->data.m[%d] %s: %s", i, hdD->name, hdD->data.m[i]);
+            }
+        }
+#endif
+    }
+    cleanup {
+        if (hdNew != NULL)
+            free((headerdata_t *)hdNew);
+    }
+    catch(ex) {
+        rethrow;
+    }
+}
+
+static void msg_headermatrixteardwn(msg_t *msg)
+{
+    ex_t ex;
+    try {
+        headerdata_t *hdI;
+
+        if (msg->azHeaders != NULL)
+            free(msg->azHeaders);
+        msg->azHeaders = NULL;
+        msg->asHeaders = 0;
+
+        for (hdI = msg->hdFirst; hdI != NULL; hdI = hdI->next) { /* for each matrix header */
+            log2(msg, DEBUG, "FIXME trace loop hdI=%.8lx, hI->name=\"%s\"", hdI, hdI->name);
+            if (hdI->name == NULL || strlen(hdI->name) == 0 || hdI->ndata == 0)
+                continue;
+            if (hdI->ndata == 0) {
+                log1(msg, DEBUG, "header=%s, no data", hdI->name);
+            }
+            else if(hdI->ndata == 1) { /* header data is single valued */
+                log2(msg, DEBUG, "header=%s, data=%s", hdI->name, hdI->data.s);
+                argz_add(&msg->azHeaders, &msg->asHeaders, hdI->name);
+                argz_add(&msg->azHeaders, &msg->asHeaders, hdI->data.s);
+            }
+            else { /* header data is multi valued */
+                int i;
+                for (i = 0; i < hdI->ndata; i++) {
+                    log3(msg, DEBUG, "header=%s[%d], data=%s", hdI->name, i, hdI->data.m[i]);
+                    argz_add(&msg->azHeaders, &msg->asHeaders, hdI->name);
+                    argz_add(&msg->azHeaders, &msg->asHeaders, hdI->data.m[i]);
+                }
+            }
+        }
+#if 0
+        { //FIXME debug code block
+            int i;
+            headerdata_t *hdD;
+
+            log0(msg, DEBUG, "FIXME trace ---------- msg_headermatrixteardwn() ----------");
+            for (hdD = msg->hdFirst; hdD != NULL; hdD = hdD->next) {
+                if (hdD->ndata == 0)
+                    log1(msg, DEBUG, "hdD->name=%s: (NO DATA)", hdD->name);
+                if (hdD->ndata == 1)
+                    log2(msg, 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(msg, DEBUG, "hdD->name:hdD->data.m[%d] %s: %s", i, hdD->name, hdD->data.m[i]);
+            }
+        }
+#endif
+    }
+    catch(ex) {
+        rethrow;
+    }
+}
+
+
 static void headerrewrite(lmtp2nntp_t *ctx)
 {
     headerrule_t *hrI;
@@ -1303,11 +1544,11 @@
     int         opt;
     char       *buf;
     int         buf_size;
-#define OVECSIZE 30
     int         ovec[OVECSIZE];
     const char **cpList;
     */
     regex_ctx_t *regex_ctx;
+#define OVECSIZE 30
     int            ovec[OVECSIZE];
 
     { //FIXME debug code block
@@ -1483,11 +1724,11 @@
 static void headersimulation(lmtp2nntp_t *ctx)
 {
     headerdata_t *hdI, *hdNew;
-
-    ctx->msg = msg_create();
+    char *replyto[4] = { "foo@example.com", "bar@example.com", "quux@example.com", NULL };
 
     log0(ctx, DEBUG, "FIXME simulation - GO");
-    char *replyto[4] = { "foo@example.com", "bar@example.com", "quux@example.com", NULL };
+
+    ctx->msg = msg_create();
 
     hdNew = headercreate();
     hdNew->name = "To";


ossp-pkg/lmtp2nntp/lmtp2nntp_msg.c 1.2 -> 1.3

--- lmtp2nntp_msg.c      2001/12/31 15:15:36     1.2
+++ lmtp2nntp_msg.c      2002/02/26 15:56:08     1.3
@@ -54,6 +54,7 @@
     msg->cpMsg = NULL;
     msg->azHeaders = NULL;
     msg->asHeaders = 0;
+    msg->hdFirst = NULL;
     msg->cpFid = NULL;
     msg->cpBody = NULL;
     msg->cpMsgid = NULL;


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

--- lmtp2nntp_option.c   2002/02/13 16:25:38     1.14
+++ lmtp2nntp_option.c   2002/02/26 15:56:08     1.15
@@ -632,6 +632,7 @@
     (void)option_register(o, "operationmode",      'o', OPT_SINGLE,  "553/5.7.1", "fakestatus or operationmode",       "abc/a.d.e|post|feed",        &stdsyntax, "m/.*/" ); //"m/([0-9]{3}\\/[0-9]\\.[0-9]\\.[0-9]|post|feed)/" ); /* 553 = Requested action not taken: mailbox name not allowed, 5.7.1 =  Delivery not authorized, message refused */
     (void)option_register(o, "restrictheader",     'r', OPT_SINGLE,  NULL,        "header restriction",                "regex",                      &stdsyntax, "m/.*/" );
     (void)option_register(o, "size",               's', OPT_SINGLE,  "8388608",   "maximum message size",              "bytes",                      &stdsyntax, "m/.*/" ); //"m/[0-9]+/" );
+    (void)option_register(o, "testfile",           't', OPT_MULTI,   NULL,        "testfile for headerrule",           "testfile",                   &stdsyntax, "m/.*/" );
     (void)option_register(o, "user",               'u', OPT_SINGLE,  NULL,        "user",                              "uid|name",                   &stdsyntax, "m/.*/" );
     (void)option_register(o, "version",            'v', OPT_FLAG,    NULL,        "print version",                     NULL,                         &stdsyntax, NULL );
     (void)option_register(o, "newsgroup",          NUL, OPT_MULTI,   NULL,        "article destination",               "newsgroup",                  &stdsyntax, "m/.*/" );

CVSTrac 2.0.1