--- lmtp2nntp.c 2001/08/14 08:15:25 1.16
+++ lmtp2nntp.c 2001/08/14 14:42:41 1.17
@@ -76,10 +76,8 @@
int option_groupmode;
int nsc;
struct ns ns[MAXNEWSSERVICES];
- char *azGroups;
- size_t asGroups;
- char *azGroupfilters;
- size_t asGroupfilters;
+ char *azGroupargs;
+ size_t asGroupargs;
struct session session;
msg_t *msg;
} lmtp2nntp_t;
@@ -104,7 +102,7 @@
int main(int argc, char **argv)
{
- //FIXME int rc = 0;
+ int rc = 0;
lmtp_t *lmtp;
lmtp_io_t lmtp_io;
lmtp2nntp_t *ctx;
@@ -138,10 +136,8 @@
ctx->ns[i].s = -1;
ctx->ns[i].nntp = NULL;
}
- ctx->azGroups = NULL;
- ctx->asGroups = 0;
- ctx->azGroupfilters = NULL;
- ctx->asGroupfilters = 0;
+ ctx->azGroupargs = NULL;
+ ctx->asGroupargs = 0;
initsession(&ctx->session);
ctx->msg = NULL;
@@ -230,12 +226,11 @@
exit(ERR_EXECUTION);
}
}
- /* remaining arguments are groups or group filters */
- for (i = optind; i < argc; i++)
- if (ctx->option_groupmode == GROUPMODE_ENVELOPE)
- argz_add(&ctx->azGroupfilters, &ctx->asGroupfilters, argv[i]);
- else
- argz_add(&ctx->azGroups, &ctx->asGroups, argv[i]);
+ /* remaining arguments are Groupargs */
+ for (i = optind; i < argc; i++) {
+ //fprintf(stderr, "DEBUG: argv[i] = ***%s***\n", argv[i]);
+ argz_add(&ctx->azGroupargs, &ctx->asGroupargs, argv[i]);
+ }
/* initialize LMTP context */
lmtp_io.select = NULL;
@@ -256,7 +251,7 @@
/* loop for LMTP protocol */
lmtp_loop(lmtp);
- return 0;
+ return rc;
}
static void resetsession(struct session *session)
@@ -348,7 +343,7 @@
bOk = FALSE;
}
if (bOk && ((rc = nntp_init(ctx->ns[i].nntp)) != NNTP_OK)) {
- //fprintf(stderr, "DEBUG: nntp_init failed: %s\n", nntp_error(ctx->ns[i].nntp, rc));
+ //fprintf(stderr, "DEBUG: nntp_init failed: %s\n", nntp_error(rc));
bOk = FALSE;
}
if (bOk)
@@ -529,7 +524,8 @@
return LMTP_ERR_MEM;
}
- if (!str_parse(req->msg, "m/^MAIL From: <(.+@.+)>$/i", &ctx->msg->mail_from)) {
+ if (!str_parse(req->msg, "m/^MAIL From:\\s*<(.+@.+)>$/i", &ctx->msg->mail_from)) {
+ //FIXME ^^^^ is this space required/ valid? Sendmail skips them!
res.statuscode = "553";
res.dsncode = "5.5.4";
res.statusmsg = "Domain name required for sender address.";
@@ -559,7 +555,8 @@
return LMTP_OK;
}
- if (!str_parse(req->msg, "m/^RCPT To: (.+)$/i", &cp)) {
+ if (!str_parse(req->msg, "m/^RCPT To:\\s*(.+)$/i", &cp)) {
+ //FIXME ^^^^ is this space required/ valid? Sendmail skips them!
res.statuscode = "501";
res.dsncode = "5.5.2";
res.statusmsg = "Syntax error in parameters.";
@@ -567,6 +564,14 @@
return LMTP_OK;
}
+ if ((cp == NULL) || (strlen(cp) == 0)) {
+ res.statuscode = "550";
+ res.dsncode = "5.1.1";
+ res.statusmsg = "nul Recipient/ Group.";
+ lmtp_response(lmtp, &res);
+ return LMTP_OK;
+ }
+
/* FIXME
* in GROUPMODE = ARG|HEADER recipient must be acknowledged and stored to
* give proper pipelining responses. in GROUPMODE = ENVELOPE recipient is
@@ -592,19 +597,11 @@
lmtp_response(lmtp, &res);
return LMTP_OK;
}
+ argz_add(&ctx->msg->azEnvgroups, &ctx->msg->asEnvgroups, group);
}
- if ((cp == NULL) || (strlen(cp) == 0)) {
- res.statuscode = "550";
- res.dsncode = "5.1.1";
- res.statusmsg = "nul Recipient/ Group.";
- lmtp_response(lmtp, &res);
- return LMTP_OK;
- }
-
//fprintf(stderr, "DEBUG: cp=***%s***\n", cp);
argz_add(&ctx->msg->azRcpt, &ctx->msg->asRcpt, cp);
- argz_add(&ctx->azGroups, &ctx->asGroups, group);
res.statuscode = "250";
res.dsncode = "2.1.5";
res.statusmsg = "Recipient/ Group accepted";
@@ -638,89 +635,114 @@
rc = lmtp_readmsg(lmtp, &ctx->msg->cpMsg, MESSAGE_MAXLEN);
if (rc == LMTP_ERR_OVERFLOW) {
+ str_format(errorstring, sizeof(errorstring), "Overflow reading message: %s", lmtp_error(rc));
+ res.statuscode = "500";
+ res.dsncode = "5.0.0";
+ res.statusmsg = errorstring; //FIXME temp or perm error?
rcpt = NULL;
while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
- res.statuscode = "500";
- res.dsncode = "5.0.0";
- res.statusmsg = "Overflow reading message"; //FIXME temp or perm error?
lmtp_response(lmtp, &res);
- return LMTP_OK;
}
+ return LMTP_OK;
}
if (rc == LMTP_ERR_SYSTEM) {
+ str_format(errorstring, sizeof(errorstring), "System error reading message: %s", strerror(errno));
+ res.statuscode = "500";
+ res.dsncode = "5.0.0";
+ res.statusmsg = errorstring;
rcpt = NULL;
while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
- res.statuscode = "500";
- res.dsncode = "5.0.0";
- str_format(errorstring, sizeof(errorstring), "System error reading message: %s", strerror(errno));
- res.statusmsg = errorstring;
lmtp_response(lmtp, &res);
- return LMTP_OK;
}
+ return LMTP_OK;
}
if(rc != LMTP_OK) {
+ str_format(errorstring, sizeof(errorstring), "Unknown error reading message: %s", lmtp_error(rc));
+ res.statuscode = "500";
+ res.dsncode = "5.0.0";
+ res.statusmsg = errorstring;
rcpt = NULL;
while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
- res.statuscode = "500";
- res.dsncode = "5.0.0";
- res.statusmsg = "Unknown error reading message"; //FIXME call lmtp_error()?
lmtp_response(lmtp, &res);
- return LMTP_OK;
}
+ return LMTP_OK;
}
- if (msg_split(ctx->msg) != MSG_OK) {
+ //fprintf(stderr, "DEBUG: before msg_split\n");
+ if ((rc = msg_split(ctx->msg)) != MSG_OK) {
+ str_format(errorstring, sizeof(errorstring), "Error splitting message: %s", msg_error(rc));
+ res.statuscode = "500";
+ res.dsncode = "5.0.0";
+ res.statusmsg = errorstring;
+ rcpt = NULL;
while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
- res.statuscode = "500";
- res.dsncode = "5.0.0";
- res.statusmsg = "Error splitting message."; //FIXME call msg_error()?
lmtp_response(lmtp, &res);
- return LMTP_OK;
}
+ return LMTP_OK;
}
+ //fprintf(stderr, "DEBUG: after msg_split\n");
- ctx->msg->azNewsgroups = ctx->azGroups;
- ctx->msg->asNewsgroups = ctx->asGroups;
+ if (ctx->option_groupmode == GROUPMODE_ENVELOPE) {
+ ctx->msg->azNewsgroups = memcpy(malloc(ctx->msg->asEnvgroups + 1), ctx->msg->azEnvgroups, ctx->msg->asEnvgroups); //FIXME strdup == NULL
+ ctx->msg->asNewsgroups = ctx->msg->asEnvgroups;
+ }
+ else if (ctx->option_groupmode == GROUPMODE_ARG) {
+ ctx->msg->azNewsgroups = memcpy(malloc(ctx->asGroupargs + 1), ctx->azGroupargs, ctx->asGroupargs); //FIXME strdup == NULL
+ ctx->msg->asNewsgroups = ctx->asGroupargs;
+ }
+ /* else keep == GROUPMODE_HEADERS */
+
+#if 0 //FIXME debug paragraph
+ rcpt = NULL;
+ while ((rcpt = argz_next(ctx->msg->azNewsgroups, ctx->msg->asNewsgroups, rcpt)) != NULL) {
+ fprintf(stderr, "DEBUG: commited group ***%s***\n", rcpt);
+ }
+#endif
- if (msg_join(ctx->msg) != MSG_OK) {
+ //fprintf(stderr, "DEBUG: before msg_join\n");
+ if ((rc = msg_join(ctx->msg)) != MSG_OK) {
+ str_format(errorstring, sizeof(errorstring), "Error joining message: %s", msg_error(rc));
+ res.statuscode = "500";
+ res.dsncode = "5.0.0";
+ res.statusmsg = errorstring;
+ rcpt = NULL;
while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
- res.statuscode = "500";
- res.dsncode = "5.0.0";
- res.statusmsg = "Error joining message."; //FIXME call msg_error()?
lmtp_response(lmtp, &res);
- return LMTP_OK;
}
+ return LMTP_OK;
}
+ //fprintf(stderr, "DEBUG: after msg_join\n");
bSuccess = FALSE;
for (i = 0; i < ctx->nsc; i++) {
//fprintf(stderr, "DEBUG: trying service %s\n", ctx->ns[i].h);
- if (nntp_post(ctx->ns[i].nntp, ctx->msg) == NNTP_OK)
+ if ((rc = nntp_post(ctx->ns[i].nntp, ctx->msg)) == NNTP_OK)
bSuccess = TRUE;
}
+ //FIXME rc has only last error
rcpt = NULL;
while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
if (bSuccess == TRUE) {
+ str_format(errorstring, sizeof(errorstring), "Message accepted for delivery to %s", rcpt);
res.statuscode = "250";
res.dsncode = "2.0.0";
- str_format(errorstring, sizeof(errorstring), "Message accepted for delivery to %s", rcpt);
res.statusmsg = errorstring;
- lmtp_response(lmtp, &res);
} else {
+ str_format(errorstring, sizeof(errorstring), "Last error posting message: %s", nntp_error(rc));
res.statuscode = "500";
res.dsncode = "5.0.0";
- res.statusmsg = "Error posting message."; //FIXME call nntp_error()?
- lmtp_response(lmtp, &res);
+ res.statusmsg = errorstring;
}
+ lmtp_response(lmtp, &res);
}
msg_destroy(ctx->msg);
ctx->msg = NULL;
- return rc;
+ return LMTP_OK;
}
static lmtp_rc_t lmtp_cb_noop(lmtp_t *lmtp, lmtp_io_t *io, lmtp_req_t *req, void *ctx)
|