Citadel API clean up.
[citadel.git] / citadel / modules / network / serv_network.c
index 2d3d8e3ca91aed859f10370f1e7670322f84663e..bb1947354e207405de3ba35d01c384f319feb872 100644 (file)
@@ -4,8 +4,21 @@
  * This module handles shared rooms, inter-Citadel mail, and outbound
  * mailing list processing.
  *
- * Copyright (C) 2000-2005 by Art Cancro and others.
- * This code is released under the terms of the GNU General Public License.
+ * Copyright (c) 2000-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * ** NOTE **   A word on the S_NETCONFIGS semaphore:
  * This is a fairly high-level type of critical section.  It ensures that no
@@ -54,7 +67,6 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
 #include "database.h"
@@ -452,6 +464,7 @@ void network_deliver_digest(SpoolControl *sc) {
        size_t recps_len = SIZ;
        struct recptypes *valid;
        namelist *nptr;
+       char bounce_to[256];
 
        if (sc->num_msgs_spooled < 1) {
                fclose(sc->digestfp);
@@ -478,6 +491,15 @@ void network_deliver_digest(SpoolControl *sc) {
        msg->cm_fields['F'] = strdup(buf);
        msg->cm_fields['R'] = strdup(buf);
 
+       /* Set the 'List-ID' header */
+       msg->cm_fields['L'] = malloc(1024);
+       snprintf(msg->cm_fields['L'], 1024,
+               "%s <%ld.list-id.%s>",
+               CC->room.QRname,
+               CC->room.QRnumber,
+               config.c_fqdn
+       );
+
        /*
         * Go fetch the contents of the digest
         */
@@ -518,10 +540,17 @@ void network_deliver_digest(SpoolControl *sc) {
                strcat(recps, nptr->name);
        }
 
+       /* Where do we want bounces and other noise to be heard?  Surely not the list members! */
+       snprintf(bounce_to, sizeof bounce_to, "room_aide@%s", config.c_fqdn);
+
        /* Now submit the message */
        valid = validate_recipients(recps, NULL, 0);
        free(recps);
-       CtdlSubmitMsg(msg, valid, NULL, 0);
+       if (valid != NULL) {
+               valid->bounce_to = strdup(bounce_to);
+               valid->envelope_from = strdup(bounce_to);
+               CtdlSubmitMsg(msg, valid, NULL, 0);
+       }
        CtdlFreeMessage(msg);
        free_recipients(valid);
 }
@@ -535,6 +564,7 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) {
        size_t recps_len = SIZ;
        struct recptypes *valid;
        namelist *nptr;
+       char bounce_to[256];
 
        /* Don't do this if there were no recipients! */
        if (sc->listrecps == NULL) return;
@@ -565,11 +595,18 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) {
                strcat(recps, nptr->name);
        }
 
+       /* Where do we want bounces and other noise to be heard?  Surely not the list members! */
+       snprintf(bounce_to, sizeof bounce_to, "room_aide@%s", config.c_fqdn);
+
        /* Now submit the message */
        valid = validate_recipients(recps, NULL, 0);
        free(recps);
-       CtdlSubmitMsg(msg, valid, NULL, 0);
-       free_recipients(valid);
+       if (valid != NULL) {
+               valid->bounce_to = strdup(bounce_to);
+               valid->envelope_from = strdup(bounce_to);
+               CtdlSubmitMsg(msg, valid, NULL, 0);
+               free_recipients(valid);
+       }
        /* Do not call CtdlFreeMessage(msg) here; the caller will free it. */
 }
 
@@ -610,6 +647,18 @@ void network_spool_msg(long msgnum, void *userdata) {
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
 
+                       /* Set the 'List-ID' header */
+                       if (msg->cm_fields['L'] != NULL) {
+                               free(msg->cm_fields['L']);
+                       }
+                       msg->cm_fields['L'] = malloc(1024);
+                       snprintf(msg->cm_fields['L'], 1024,
+                               "%s <%ld.list-id.%s>",
+                               CC->room.QRname,
+                               CC->room.QRnumber,
+                               config.c_fqdn
+                       );
+
                        /* Prepend "[List name]" to the subject */
                        if (msg->cm_fields['U'] == NULL) {
                                msg->cm_fields['U'] = strdup("(no subject)");
@@ -1092,7 +1141,7 @@ void network_spoolout_room(char *room_to_spool) {
         * Normally this should never happen, but once in a while maybe a room gets
         * queued for networking and then deleted before it can happen.
         */
-       if (getroom(&CC->room, room_to_spool) != 0) {
+       if (CtdlGetRoom(&CC->room, room_to_spool) != 0) {
                CtdlLogPrintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", room_to_spool);
                return;
        }
@@ -2083,7 +2132,7 @@ void *network_do_queue(void *args) {
        struct CitContext networkerCC;
 
        /* Give the networker its own private CitContext */
-       CtdlFillPrivateContext(&networkerCC, "network");
+       CtdlFillSystemContext(&networkerCC, "network");
        citthread_setspecific(MyConKey, (void *)&networkerCC );
 
        /*
@@ -2125,7 +2174,7 @@ void *network_do_queue(void *args) {
         */
        if (full_processing && !CtdlThreadCheckStop()) {
                CtdlLogPrintf(CTDL_DEBUG, "network: loading outbound queue\n");
-               ForEachRoom(network_queue_room, NULL);
+               CtdlForEachRoom(network_queue_room, NULL);
        }
 
        if (rplist != NULL) {
@@ -2201,9 +2250,8 @@ void cmd_netp(char *cmdbuf)
        extract_token(pass, cmdbuf, 1, '|', sizeof pass);
 
        if (doing_queue) {
-               CtdlLogPrintf(CTDL_WARNING, "Network node <%s> refused - spooling", node);
-               cprintf("%d spooling - try again in a few minutes\n",
-                       ERROR + RESOURCE_BUSY);
+               CtdlLogPrintf(CTDL_WARNING, "Network node <%s> refused - spooling\n", node);
+               cprintf("%d spooling - try again in a few minutes\n", ERROR + RESOURCE_BUSY);
                return;
        }
 
@@ -2212,16 +2260,21 @@ void cmd_netp(char *cmdbuf)
        v = is_valid_node(nexthop, secret, node);
 
        if (v != 0) {
-               snprintf (err_buf, sizeof(err_buf), "Unknown node <%s>\n", node);
+               snprintf(err_buf, sizeof err_buf,
+                       "An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
+                       node, CC->cs_host, CC->cs_addr
+               );
                CtdlLogPrintf(CTDL_WARNING, err_buf);
-               cprintf("%d authentication failed\n",
-                       ERROR + PASSWORD_REQUIRED);
+               cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
                aide_message(err_buf, "IGNet Networking.");
                return;
        }
 
        if (strcasecmp(pass, secret)) {
-               snprintf (err_buf, sizeof(err_buf), "Bad password for network node <%s>", node);
+               snprintf(err_buf, sizeof err_buf,
+                       "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
+                       CC->cs_host, CC->cs_addr, node
+               );
                CtdlLogPrintf(CTDL_WARNING, err_buf);
                cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
                aide_message(err_buf, "IGNet Networking.");
@@ -2236,17 +2289,20 @@ void cmd_netp(char *cmdbuf)
 
        safestrncpy(CC->net_node, node, sizeof CC->net_node);
        network_talking_to(node, NTT_ADD);
-       CtdlLogPrintf(CTDL_NOTICE, "Network node <%s> logged in\n", CC->net_node);
-       cprintf("%d authenticated as network node '%s'\n", CIT_OK,
-               CC->net_node);
+       CtdlLogPrintf(CTDL_NOTICE, "Network node <%s> logged in from %s [%s]\n",
+               CC->net_node, CC->cs_host, CC->cs_addr
+       );
+       cprintf("%d authenticated as network node '%s'\n", CIT_OK, CC->net_node);
 }
 
+
 int network_room_handler (struct ctdlroom *room)
 {
        network_queue_room(room, NULL);
        return 0;
 }
 
+
 /*
  * Module entry point
  */