stable now but there are GIANT PIECES MISSING
[citadel.git] / citadel / modules / network / serv_network.c
1 /*
2  * This module handles network mail and mailing list processing.
3  *
4  * Copyright (c) 2000-2021 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * ** NOTE **   A word on the S_NETCONFIGS semaphore:
15  * This is a fairly high-level type of critical section.  It ensures that no
16  * two threads work on the netconfigs files at the same time.  Since we do
17  * so many things inside these, here are the rules:
18  *  1. begin_critical_section(S_NETCONFIGS) *before* begin_ any others.
19  *  2. Do *not* perform any I/O with the client during these sections.
20  */
21
22 /*
23  * Duration of time (in seconds) after which pending list subscribe/unsubscribe
24  * requests that have not been confirmed will be deleted.
25  */
26 #define EXP     259200  /* three days */
27
28 #include "sysdep.h"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <stdio.h>
32 #include <fcntl.h>
33 #include <ctype.h>
34 #include <signal.h>
35 #include <pwd.h>
36 #include <errno.h>
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <dirent.h>
40 #include <time.h>
41
42 #ifdef HAVE_SYSCALL_H
43 # include <syscall.h>
44 #else 
45 # if HAVE_SYS_SYSCALL_H
46 #  include <sys/syscall.h>
47 # endif
48 #endif
49
50 #include <sys/wait.h>
51 #include <string.h>
52 #include <limits.h>
53 #include <libcitadel.h>
54 #include "citadel.h"
55 #include "server.h"
56 #include "citserver.h"
57 #include "support.h"
58 #include "config.h"
59 #include "user_ops.h"
60 #include "database.h"
61 #include "msgbase.h"
62 #include "internet_addressing.h"
63 #include "serv_network.h"
64 #include "clientsocket.h"
65 #include "citadel_dirs.h"
66 #include "threads.h"
67 #include "context.h"
68 #include "ctdl_module.h"
69 #include "netspool.h"
70 #include "netmail.h"
71
72 /* comes from lookup3.c from libcitadel... */
73 extern uint32_t hashlittle( const void *key, size_t length, uint32_t initval);
74
75 /*
76  * network_do_queue()
77  * 
78  * Run through the rooms doing various types of network stuff.
79  */
80 void network_do_queue(void) {
81         static time_t last_run = 0L;
82         int full_processing = 1;
83
84         /*
85          * Run the full set of processing tasks no more frequently
86          * than once every n seconds
87          */
88         if ( (time(NULL) - last_run) < CtdlGetConfigLong("c_net_freq") ) {
89                 full_processing = 0;
90                 syslog(LOG_DEBUG, "network: full processing in %ld seconds.", CtdlGetConfigLong("c_net_freq") - (time(NULL)- last_run));
91         }
92
93         begin_critical_section(S_RPLIST);
94         end_critical_section(S_RPLIST);
95
96         /* 
97          * Go ahead and run the queue
98          */
99         if (full_processing && !server_shutting_down) {
100                 syslog(LOG_DEBUG, "network: loading outbound queue");
101                 //CtdlForEachNetCfgRoom(network_queue_interesting_rooms, &RL);
102                 // FIXME do the outbound crapola AJC 2021
103         }
104         syslog(LOG_DEBUG, "network: queue run completed");
105
106         if (full_processing) {
107                 last_run = time(NULL);
108         }
109 }
110
111
112 /*
113  * Module entry point
114  */
115 CTDL_MODULE_INIT(network)
116 {
117         if (!threading)
118         {
119                 CtdlRegisterSessionHook(network_do_queue, EVT_TIMER, PRIO_QUEUE + 10);
120         }
121         return "network";
122 }