+
+/*
+ * Bounce a message back to the sender
+ */
+void network_bounce(struct CtdlMessage *msg, char *reason) {
+ static int serialnum = 0;
+ FILE *fp;
+ char filename[SIZ];
+ struct ser_ret sermsg;
+ char *oldpath = NULL;
+ char buf[SIZ];
+
+ lprintf(9, "entering network_bounce()\n");
+
+ if (msg == NULL) return;
+
+ /*
+ * Give it a fresh message ID
+ */
+ if (msg->cm_fields['I'] != NULL) {
+ phree(msg->cm_fields['I']);
+ }
+ sprintf(buf, "%ld.%04x.%04x@%s",
+ time(NULL), getpid(), ++serialnum, config.c_fqdn);
+ msg->cm_fields['I'] = strdoop(buf);
+
+ /*
+ * FIXME ... right now we're just sending a bounce; we really want to
+ * include the text of the bounced message.
+ */
+ if (msg->cm_fields['M'] != NULL) {
+ phree(msg->cm_fields['M']);
+ }
+ msg->cm_fields['M'] = strdoop(reason);
+ msg->cm_format_type = 0;
+
+ /*
+ * Turn the message around
+ */
+ if (msg->cm_fields['R'] == NULL) {
+ phree(msg->cm_fields['R']);
+ }
+
+ if (msg->cm_fields['D'] == NULL) {
+ phree(msg->cm_fields['D']);
+ }
+
+ msg->cm_fields['R'] = msg->cm_fields['A'];
+ msg->cm_fields['D'] = msg->cm_fields['N'];
+ msg->cm_fields['A'] = strdoop(BOUNCESOURCE);
+ msg->cm_fields['N'] = strdoop(config.c_nodename);
+
+ if (!strcasecmp(msg->cm_fields['D'], config.c_nodename)) {
+ phree(msg->cm_fields['D']);
+ }
+
+ /*
+ * If this is a bounce of a bounce, send it to the Aide> room
+ * instead of looping around forever
+ */
+ if (msg->cm_fields['D'] == NULL) if (msg->cm_fields['R'] != NULL)
+ if (!strcasecmp(msg->cm_fields['R'], BOUNCESOURCE)) {
+ phree(msg->cm_fields['R']);
+ if (msg->cm_fields['C'] != NULL) {
+ phree(msg->cm_fields['C']);
+ }
+ msg->cm_fields['C'] = strdoop(AIDEROOM);
+ }
+
+ /* prepend our node to the path */
+ if (msg->cm_fields['P'] != NULL) {
+ oldpath = msg->cm_fields['P'];
+ msg->cm_fields['P'] = NULL;
+ }
+ else {
+ oldpath = strdoop("unknown_user");
+ }
+ msg->cm_fields['P'] = mallok(strlen(oldpath) + SIZ);
+ sprintf(msg->cm_fields['P'], "%s!%s", config.c_nodename, oldpath);
+ phree(oldpath);
+
+ /* serialize the message */
+ serialize_message(&sermsg, msg);
+
+ /* now send it */
+ sprintf(filename, "./network/spoolin/bounce.%04x.%04x",
+ getpid(), serialnum);
+
+ fp = fopen(filename, "ab");
+ if (fp != NULL) {
+ fwrite(sermsg.ser,
+ sermsg.len, 1, fp);
+ fclose(fp);
+ }
+ phree(sermsg.ser);
+ CtdlFreeMessage(msg);
+ lprintf(9, "leaving network_bounce()\n");
+}
+
+
+
+