--- lmtp2nntp_msg.c 2002/04/24 09:26:03 1.9
+++ lmtp2nntp_msg.c 2002/04/25 09:14:28 1.10
@@ -31,6 +31,8 @@
#include "lmtp2nntp_argz.h"
#include "fixme.h" //FIMXE logbook only
#include "tai.h"
+#include <sys/utsname.h> //FIXME createmessageid() hack
+
#include "str.h"
@@ -694,6 +696,35 @@
}
#undef MAXOUT //FIXME is there a better way to do it?
+static var_rc_t createmessageid(
+ 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!
+
+ 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);
+ }
+
+ /* idea and first implementation as a contribution to lmtp2nntp v1.0.0
+ by Christos Ricudis <ricudis@paiko.gr> */
+
+ 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);
+ return VAR_OK;
+}
+
static var_rc_t operate_cb(
var_t *var, void *ctx,
const char *op_ptr, size_t op_len,
@@ -709,20 +740,15 @@
*out_size = 0;
return VAR_OK;
}
- if (op_len == 6 && strncmp(op_ptr, "return", 6) == 0) {
+ 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 == 5 && strncmp(op_ptr, "upper", 5) == 0) {
- *out_ptr = malloc(val_len);
- *out_len = val_len;
- *out_size = val_len;
- for (i = 0; i < val_len; i++)
- (*out_ptr)[i] = (char)toupper((int)(val_ptr[i]));
- 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);
}
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);
|