OSSP CVS Repository

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

Check-in Number: 2155
Date: 2002-May-27 17:09:50 (local)
2002-May-27 15:09:50 (UTC)
User:thl
Branch:
Comment: createmessageid now using lib_val; added support for long nodenames
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/fixme.h      1.22 -> 1.23     3 inserted, 1 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.72 -> 1.73     11 inserted, 4 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_main.c      1.54 -> 1.55     30 inserted, 9 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_msg.c      1.14 -> 1.15     69 inserted, 29 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_msg.h      1.5 -> 1.6     4 inserted, 3 deleted

ossp-pkg/lmtp2nntp/fixme.h 1.22 -> 1.23

--- fixme.h      2002/03/13 14:41:13     1.22
+++ fixme.h      2002/05/27 15:09:50     1.23
@@ -60,6 +60,7 @@
 
 typedef struct {
     l2_context_t    ctx;
+    val_t          *prival;
     val_t          *val;
     char           *progname;
     int             option_groupmode;
@@ -74,6 +75,7 @@
     int             option_timeout_nntp_connect;
     int             option_timeout_nntp_read;
     int             option_timeout_nntp_write;
+    char           *option_nodename;
     char           *option_mailfrom;
     char           *option_restrictheader;
     char           *option_pidfile;
@@ -100,9 +102,9 @@
     size_t          asGroupargs;
     struct          session session;
     msg_t          *msg;
-    struct utsname  uname;
     var_t          *config_varregex;
     var_t          *config_varctx;
+    int             msgcount; /* number of messages processed, used for creating unique ids */
 } lmtp2nntp_t;
 
 #define ERR_EXECUTION 1


ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.72 -> 1.73

--- lmtp2nntp_config.c   2002/04/18 15:38:59     1.72
+++ lmtp2nntp_config.c   2002/05/27 15:09:50     1.73
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <sys/utsname.h>
 #include <errno.h>
 #include <pwd.h>
 
@@ -733,11 +734,16 @@
         logbook(ctx->l2, L2_LEVEL_TRACE, "--nodename = \"%s\"", ov->data.s);
 
         if (ov->ndata == 1) {
-            if (strlen(ov->data.s) > sizeof(ctx->uname.nodename)-1) {
-                logbook(ctx->l2, L2_LEVEL_ERROR, "option --nodename, name (%s) too long", ov->data.s);
+            ctx->option_nodename = strdupex(ov->data.s);
+        }
+        else {
+            struct utsname name;
+
+            if (uname(&name) == -1) {
+                logbook(ctx->l2, L2_LEVEL_ERROR, "option --nodename, uname() failed %m");
                 throw(0,0,0);
             }
-            strcpy(ctx->uname.nodename, ov->data.s);
+            ctx->option_nodename = strdupex(name.nodename);
         }
     }
     catch (ex)
@@ -1106,7 +1112,8 @@
                     msg_rc_t rc;
 
                     try {
-                        if ((msg = msg_create()) == NULL) throw(0, 0, "msg_create");
+                        ctx->msgcount++;
+                        if ((msg = msg_create(ctx->prival)) == NULL) throw(0, 0, "msg_create");
                         msg->l2 = ctx->l2;
                         msg->cpMsg = cpBuf;
                         if ((rc = msg_split((msg_t *)msg)) != MSG_OK) {


ossp-pkg/lmtp2nntp/lmtp2nntp_main.c 1.54 -> 1.55

--- lmtp2nntp_main.c     2002/04/18 15:38:21     1.54
+++ lmtp2nntp_main.c     2002/05/27 15:09:50     1.55
@@ -376,6 +376,7 @@
     if ((ctx = (lmtp2nntp_t *)malloc(sizeof(lmtp2nntp_t))) == NULL)
         CU(ERR_EXECUTION);
     ctx->ctx.vp = ctx;
+    ctx->prival = NULL;
     ctx->val = NULL;
     ctx->progname = NULL;
     ctx->option_groupmode = GROUPMODE_UNDEF;
@@ -390,6 +391,7 @@
     ctx->option_timeout_nntp_connect = 0;
     ctx->option_timeout_nntp_read    = 0;
     ctx->option_timeout_nntp_write   = 0;
+    ctx->option_nodename = NULL;
     ctx->option_mailfrom = NULL;
     ctx->option_restrictheader = NULL;
     ctx->option_pidfile = NULL;
@@ -416,17 +418,29 @@
     ctx->asGroupargs = 0;
     initsession(&ctx->session);
     ctx->msg = NULL;
-    memset(&ctx->uname, 0, sizeof(struct utsname));
     ctx->config_varregex = NULL;
     ctx->config_varctx = NULL;
+    ctx->msgcount = 0;
     
-    /* fill in application context */
+    /* private application context */
+    if (val_create(&ctx->prival) != VAL_OK)
+        CU(ERR_EXECUTION);
+
+    /* create printable variables context and mount it into the private application context */
     if (val_create(&ctx->val) != VAL_OK)
         CU(ERR_EXECUTION);
-    if (uname(&ctx->uname) == -1) {
-        fprintf(stderr, "%s:Error: uname failed \"%s\"\n", ctx->progname, strerror(errno));
+    if (val_reg(ctx->prival, "printable", VAL_TYPE_VAL, "printable variables", NULL) != VAL_OK)
         CU(ERR_EXECUTION);
-    }
+    if (val_set(ctx->prival, "printable", ctx->val) != VAL_OK)
+        CU(ERR_EXECUTION);
+
+    /* feed lib_val */
+    if (val_reg(ctx->prival, "msgcount", VAL_TYPE_INT, "number of messages processed so far", (void *)&ctx->msgcount) != VAL_OK)
+        CU(ERR_EXECUTION);
+    if (val_reg(ctx->prival, "nodename", VAL_TYPE_PTR, "nodename configured or uname(3)", (void *)&ctx->option_nodename) != VAL_OK)
+        CU(ERR_EXECUTION);
+
+    /* set progname */
     ctx->progname = strdup(argv[0]);
 
     /* establish variable expansion context */
@@ -448,6 +462,7 @@
         }
     }
 
+
     /* read in the arguments */
     {
         lmtp2nntp_option_rc_t rv;
@@ -700,6 +715,8 @@
     //FIXME if (ctx->azHeaderValuePairs != NULL) free(ctx->azHeaderValuePairs); what about headerrules
     if (ctx->option_pidfile != NULL)
         free(ctx->option_pidfile);
+    if (ctx->option_nodename != NULL)
+        free(ctx->option_nodename);
     if (ctx->progname != NULL)
         free(ctx->progname);
     if (ctx->azGroupargs != NULL)
@@ -713,6 +730,7 @@
     str_parse(NULL, NULL);
     if (o != NULL)
         (void)option_destroy(o);
+    //FIXME check if anything initialized in the lmtp2nntp_t structure is destroyed here (val, prival ...)
 
     return rc;
 }
@@ -900,7 +918,7 @@
                "DSN\n"                               /* RFC1894 */
                "PIPELINING\n"                        /* RFC1854 */
                "8BITMIME",                           /* RFC1652 */
-               ctx->uname.nodename,
+               ctx->option_nodename,
                ctx->session.lhlo_domain);
     res.statuscode = "250";
     res.dsncode    = NULL; /* DSN not used for greeting */
@@ -1100,7 +1118,8 @@
      *  RFC1893 3.5 Network and Routing Status          X.3.1   Mail system full 
      */
     logbook(ctx->l2, L2_LEVEL_TRACE, "msg_create");
-    if ((ctx->msg = msg_create()) == NULL) {
+    ctx->msgcount++;
+    if ((ctx->msg = msg_create(ctx->prival)) == NULL) {
         res.statuscode = "452";
         res.dsncode    = "4.3.1";
         res.statusmsg  = "Internal error - memory.";
@@ -1402,7 +1421,8 @@
              *  RFC1893 2. Status Codes                         4.X.X   Persistent Transient Failure
              *  RFC1893 3.5 Network and Routing Status          X.3.1   Mail system full 
              */
-            if ((ctx->msg = msg_create()) == NULL) {
+            ctx->msgcount++;
+            if ((ctx->msg = msg_create(ctx->prival)) == NULL) {
                 res.statuscode = "452";
                 res.dsncode    = "4.3.1";
                 res.statusmsg  = "Internal error - memory.";
@@ -1419,7 +1439,8 @@
              *  RFC1893 2. Status Codes                         4.X.X   Persistent Transient Failure
              *  RFC1893 3.5 Network and Routing Status          X.3.1   Mail system full 
              */
-            if ((ctx->msg = msg_create()) == NULL) {
+            ctx->msgcount++;
+            if ((ctx->msg = msg_create(ctx->prival)) == NULL) {
                 res.statuscode = "452";
                 res.dsncode    = "4.3.1";
                 res.statusmsg  = "Internal error - memory.";


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

--- lmtp2nntp_msg.c      2002/05/23 09:37:15     1.14
+++ lmtp2nntp_msg.c      2002/05/27 15:09:50     1.15
@@ -31,9 +31,6 @@
 #include "lmtp2nntp_argz.h"
 #include "fixme.h" //FIMXE logbook only
 #include "tai.h"
-#include <sys/utsname.h> //FIXME createmessageid() hack
-
-
 #include "str.h"
 
 /* third party */
@@ -46,10 +43,14 @@
 #include "dmalloc.h"
 #endif
 
-msg_t *msg_create(void)
+msg_t *msg_create(val_t *prival)
 {
+    ex_t ex;
     msg_t *msg;
 
+    if (prival == NULL)
+        return NULL;
+
     if ((msg = (msg_t *)malloc(sizeof(msg_t))) == NULL)
         return NULL;
 
@@ -68,6 +69,15 @@
     msg->azNewsgroups = NULL;
     msg->asNewsgroups = 0;
     msg->l2 = NULL; /* this is a copy only */
+    msg->prival = prival;
+
+    /* create printable variables context and mount it into the private application context */
+    try {
+        val_reg(msg->prival, "msg", VAL_TYPE_PTR, "msg context structure", NULL);
+        val_set(msg->prival, "msg", msg);
+        }
+    catch (ex)
+        rethrow;
 
     return msg;
 }
@@ -96,6 +106,8 @@
     if (msg->azNewsgroups != NULL)
         free(msg->azNewsgroups);
     msg->l2 = NULL; /* this is a copy only, the "parent" needs to clean this up */
+    if (msg->prival != NULL)
+        val_unreg(msg->prival, "msg");
 
     free(msg);
     return;
@@ -559,6 +571,7 @@
 }
 
 static var_rc_t canonifydate(
+    val_t *prival,
     const char  *cpArg,  size_t nArg,
     const char  *cpVal,  size_t nVal,
           char **cppOut, size_t *pnOut, size_t *pnOutsize)
@@ -680,28 +693,61 @@
 }
 
 static var_rc_t createmessageid(
+    val_t *prival,
     const char  *cpArg,  size_t nArg,
     const char  *cpVal,  size_t nVal,
           char **cppOut, size_t *pnOut, size_t *pnOutsize)
 {
     char *cp;
-    static int mcounter = 0; //FIXME no statics in this program!
+    int msgcount;
+    msg_t *msg;
+    char *foreignid;
+    char *nodename;
+    time_t cachetime;
+    pid_t cachepid;
+    int size;
+    int maxsize;
+    char *format;
+
+    if (val_get(prival, "msgcount", &msgcount) != VAL_OK)
+        msgcount = 0;
 
-    struct utsname name; //FIXME this must be taken from global - requires context
-    if (uname(&name) == -1) {
-        memcpy(name.nodename, "localhost.invalid", strlen("localhost.invalid") + 1);
+    if (val_get(prival, "msg", &msg) != VAL_OK)
+        msg = NULL;
+
+    if (msg != NULL && msg->cpFid != NULL)
+        foreignid = msg->cpFid;
+    else
+        foreignid = "noFid";
+
+    if (val_get(prival, "nodename", &nodename) != VAL_OK)
+        nodename = "localhost.invalid";
+
+    cachetime = time(NULL);
+    cachepid = getpid();
+
+    /* idea and first implementation as a contribution to lmtp2nntp v1.0.0 by Christos Ricudis <ricudis@paiko.gr> */
+
+    maxsize = WRAPAT - strlen("Message-ID: ");
+    format = "<%0.11d$%0.6d$%0.4d$%.20s@%s>";
+    size = str_format(NULL, -1, format, cachetime, cachepid, msgcount, foreignid, nodename);
+    if (size >= 38) {
+        if (size > maxsize)
+            size = maxsize;
+        cp = (char *)mallocex(size + 1);
+        size = str_format(cp, size + 1, format, cachetime, cachepid, msgcount, foreignid, nodename);
+        if (size > maxsize)
+            cp[size-2] = '>';
     }
+    else
+        cp = strdupex("<>"); /* if format fails, do not end the wholly program abnormally */
 
-    /* idea and first implementation as a contribution to lmtp2nntp v1.0.0
-       by Christos Ricudis <ricudis@paiko.gr> */
+    if (msg != NULL) {
+        if (msg->cpMsgid != NULL)
+            free(msg->cpMsgid);
+        msg->cpMsgid = strdupex(cp);
+    }
 
-    cp = (char *)malloc( 100); //FIXME how much exacly?
-    str_format(cp, 100, "<%0.11d$%0.6d$%0.2d$%.20s$@%.40s>",
-            time(NULL), getpid(), mcounter++, "noFid" /*FIXME ((msg->cpFid == NULL)?"noFid":(msg->cpFid))*/, name.nodename);
-    /*if (msg->cpMsgid != NULL)
-        free(msg->cpMsgid);
-    msg->cpMsgid = cp; //FIXME what about aligning lib_val here?
-    */
     *cppOut    = strdupex(cp);
     *pnOutsize = strlen(cp) + 1;
     *pnOut     = strlen(cp);
@@ -709,32 +755,26 @@
 }
 
 static var_rc_t operate_cb(
-    var_t *var, void *ctx,
+    var_t *var, void *_prival,
     const char  *op_ptr, size_t op_len,
     const char  *arg_ptr, size_t arg_len,
     const char  *val_ptr, size_t val_len,
     char **out_ptr, size_t *out_len, size_t *out_size)
 {
+    val_t *prival = _prival;
     int i;
 
     if (val_ptr == NULL) {
-        *out_ptr = "";
+        *out_ptr = ""; //FIXME will lib_val try to free() this?
         *out_len = 0;
         *out_size = 0;
         return VAR_OK;
     }
-    if (op_len == 6 && strncmp(op_ptr, "return", 6) == 0) { //FIXME needless block
-        *out_ptr = malloc(arg_len);
-        *out_len = arg_len;
-        *out_size = arg_len;
-        memcpy(*out_ptr, arg_ptr, arg_len);
-        return VAR_OK;
-    }
     else if (op_len == 15 && strncmp(op_ptr, "createmessageid", 15) == 0) {
-        return createmessageid(arg_ptr, arg_len, val_ptr, val_len, out_ptr, out_len, out_size);
+        return createmessageid(prival, arg_ptr, arg_len, val_ptr, val_len, out_ptr, out_len, out_size);
     }
     else if (op_len == 12 && strncmp(op_ptr, "canonifydate", 12) == 0) {
-        return canonifydate(arg_ptr, arg_len, val_ptr, val_len, out_ptr, out_len, out_size);
+        return canonifydate   (prival, arg_ptr, arg_len, val_ptr, val_len, out_ptr, out_len, out_size);
     }
     else 
         return VAR_ERR_UNDEFINED_OPERATION;
@@ -882,7 +922,7 @@
         logbook(ctx->l2, L2_LEVEL_ERROR, "configure regex callback failed with %s (%d)", var_strerror(ctx->config_varregex, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
         throw(0,0,0);
     }
-    if ((rc = var_config(ctx->config_varctx, VAR_CONFIG_CB_OPERATION, operate_cb, NULL)) != VAR_OK) { //FIXME isn't main a better place to do this?
+    if ((rc = var_config(ctx->config_varctx, VAR_CONFIG_CB_OPERATION, operate_cb, ctx->prival)) != VAR_OK) { //FIXME isn't main a better place to do this?
         logbook(ctx->l2, L2_LEVEL_ERROR, "configure operate callback failed with %s (%d)", var_strerror(ctx->config_varctx, rc, &cp) == VAR_OK ? cp : "Unknown Error", rc);
         throw(0,0,0);
     }


ossp-pkg/lmtp2nntp/lmtp2nntp_msg.h 1.5 -> 1.6

--- lmtp2nntp_msg.h      2002/05/23 09:37:15     1.5
+++ lmtp2nntp_msg.h      2002/05/27 15:09:50     1.6
@@ -30,7 +30,7 @@
 #include <sys/types.h>
 
 #include "l2.h"
-
+#include "val.h"
 #include "lmtp2nntp_global.h"
 
 typedef struct {
@@ -48,7 +48,8 @@
     size_t  asRcpt;
     char   *azNewsgroups;
     size_t  asNewsgroups;
-    l2_channel_t *l2;
+    l2_channel_t *l2;     /* logging context, inherited as a copy from parent */
+    val_t  *prival;       /* access to private application context */
 } msg_t;
 
 struct regex_ctx_st;
@@ -81,7 +82,7 @@
     MSG_ERR_ARG
 } msg_rc_t;
 
-msg_t    *msg_create(void);
+msg_t    *msg_create(val_t *);
 msg_rc_t  msg_split(msg_t *);
 msg_rc_t  msg_join(msg_t *);
 void      msg_destroy(msg_t *);

CVSTrac 2.0.1