2 * This module handles shared rooms, inter-Citadel mail, and outbound
3 * mailing list processing.
5 * Copyright (c) 2000-2012 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * ** NOTE ** A word on the S_NETCONFIGS semaphore:
16 * This is a fairly high-level type of critical section. It ensures that no
17 * two threads work on the netconfigs files at the same time. Since we do
18 * so many things inside these, here are the rules:
19 * 1. begin_critical_section(S_NETCONFIGS) *before* begin_ any others.
20 * 2. Do *not* perform any I/O with the client during these sections.
25 * Duration of time (in seconds) after which pending list subscribe/unsubscribe
26 * requests that have not been confirmed will be deleted.
28 #define EXP 259200 /* three days */
40 #include <sys/types.h>
42 #if TIME_WITH_SYS_TIME
43 # include <sys/time.h>
47 # include <sys/time.h>
55 # if HAVE_SYS_SYSCALL_H
56 # include <sys/syscall.h>
63 #include <libcitadel.h>
66 #include "citserver.h"
72 #include "internet_addressing.h"
73 #include "serv_network.h"
74 #include "clientsocket.h"
75 #include "citadel_dirs.h"
79 #include "ctdl_module.h"
91 #define IFTODT(mode) (((mode) & 0170000) >> 12)
92 #define DTTOIF(dirtype) ((dirtype) << 12)
96 void ParseLastSent(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
99 nptr = (RoomNetCfgLine *)
100 malloc(sizeof(RoomNetCfgLine));
101 memset(nptr, 0, sizeof(RoomNetCfgLine));
102 OneRNCFG->lastsent = extract_long(LinePos, 0);
103 OneRNCFG->NetConfigs[ThisOne->C] = nptr;
106 void ParseRoomAlias(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *rncfg)
108 if (rncfg->Sender != NULL)
111 ParseGeneric(ThisOne, Line, LinePos, rncfg);
112 rncfg->Sender = NewStrBufDup(rncfg->NetConfigs[roommailalias]->Value[0]);
115 void ParseSubPendingLine(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
117 if (time(NULL) - extract_long(LinePos, 3) > EXP)
118 return; /* expired subscription... */
120 ParseGeneric(ThisOne, Line, LinePos, OneRNCFG);
122 void ParseUnSubPendingLine(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
124 if (time(NULL) - extract_long(LinePos, 2) > EXP)
125 return; /* expired subscription... */
127 ParseGeneric(ThisOne, Line, LinePos, OneRNCFG);
131 void SerializeLastSent(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *RNCfg, RoomNetCfgLine *data)
133 StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
134 StrBufAppendPrintf(OutputBuffer, "|%ld\n", RNCfg->lastsent);
137 void DeleteLastSent(const CfgLineType *ThisOne, RoomNetCfgLine **data)
143 static const RoomNetCfg SpoolCfgs [4] = {
150 static const long SpoolCfgsCopyN [4] = {
154 int HaveSpoolConfig(OneRoomNetCfg* RNCfg)
158 for (i=0; i < 4; i++) if (RNCfg->NetConfigs[SpoolCfgs[i]] == NULL) interested = 1;
162 void Netmap_AddMe(struct CtdlMessage *msg, const char *defl, long defllen)
167 /* prepend our node to the path */
168 if (CM_IsEmpty(msg, eMessagePath)) {
169 CM_SetField(msg, eMessagePath, defl, defllen);
171 node_len = configlen.c_nodename;
174 memcpy(buf, config.c_nodename, node_len);
176 buf[node_len + 1] = '\0';
177 CM_PrependToField(msg, eMessagePath, buf, node_len + 1);
180 void InspectQueuedRoom(SpoolControl **pSC,
181 RoomProcList *room_to_spool,
182 HashList *working_ignetcfg,
183 HashList *the_netmap)
188 sc = (SpoolControl*)malloc(sizeof(SpoolControl));
189 memset(sc, 0, sizeof(SpoolControl));
190 sc->RNCfg = room_to_spool->OneRNCfg;
191 sc->lastsent = room_to_spool->lastsent;
192 sc->working_ignetcfg = working_ignetcfg;
193 sc->the_netmap = the_netmap;
196 * If the room doesn't exist, don't try to perform its networking tasks.
197 * Normally this should never happen, but once in a while maybe a room gets
198 * queued for networking and then deleted before it can happen.
200 if (CtdlGetRoom(&sc->room, room_to_spool->name) != 0) {
201 syslog(LOG_CRIT, "ERROR: cannot load <%s>\n", room_to_spool->name);
205 if (sc->room.QRhighest <= sc->lastsent)
207 syslog(LOG_DEBUG, "nothing to do for <%s>\n", room_to_spool->name);
212 if (sc->RNCfg == NULL)
213 sc->RNCfg = CtdlGetNetCfgForRoom(sc->room.QRnumber);
215 if (!HaveSpoolConfig(sc->RNCfg))
218 /* nothing to do for this room... */
222 /* Now lets remember whats needed for the actual work... */
224 for (i=0; i < 4; i++)
226 aggregate_recipients(&sc->Users[SpoolCfgs[i]],
232 if (StrLength(sc->RNCfg->Sender) > 0)
233 sc->Users[roommailalias] = NewStrBufDup(sc->RNCfg->Sender);
240 void CalcListID(SpoolControl *sc)
245 struct CitContext *CCC = CC;
246 char filename[PATH_MAX];
247 #define MAX_LISTIDLENGTH 150
249 assoc_file_name(filename, sizeof filename, &sc->room, ctdl_info_dir);
250 fd = open(filename, 0);
255 if ((fstat(fd, &stbuf) == 0) &&
258 sc->RoomInfo = NewStrBufPlain(NULL, stbuf.st_size + 1);
259 StrBufReadBLOB(sc->RoomInfo, &fd, 0, stbuf.st_size, &err);
264 sc->ListID = NewStrBufPlain(NULL, 1024);
265 if (StrLength(sc->RoomInfo) > 0)
267 const char *Pos = NULL;
268 StrBufSipLine(sc->ListID, sc->RoomInfo, &Pos);
270 if (StrLength(sc->ListID) > MAX_LISTIDLENGTH)
272 StrBufCutAt(sc->ListID, MAX_LISTIDLENGTH, NULL);
273 StrBufAppendBufPlain(sc->ListID, HKEY("..."), 0);
275 StrBufAsciify(sc->ListID, ' ');
279 StrBufAppendBufPlain(sc->ListID, CCC->room.QRname, -1, 0);
282 StrBufAppendBufPlain(sc->ListID, HKEY("<"), 0);
283 RoomName = NewStrBufPlain (sc->room.QRname, -1);
284 StrBufAsciify(RoomName, '_');
285 StrBufReplaceChars(RoomName, ' ', '_');
287 if (StrLength(sc->Users[roommailalias]) > 0)
292 Pos = StrLength(sc->ListID);
293 StrBufAppendBuf(sc->ListID, sc->Users[roommailalias], 0);
294 AtPos = strchr(ChrPtr(sc->ListID) + Pos, '@');
298 StrBufPeek(sc->ListID, AtPos, 0, '.');
303 StrBufAppendBufPlain(sc->ListID, HKEY("room_"), 0);
304 StrBufAppendBuf(sc->ListID, RoomName, 0);
305 StrBufAppendBufPlain(sc->ListID, HKEY("."), 0);
306 StrBufAppendBufPlain(sc->ListID, config.c_fqdn, -1, 0);
309 * roomname <Room-Number.list-id.fqdn>
310 * according to rfc2919.txt it only has to be a uniq identifier
311 * under the domain of the system;
312 * in general MUAs use it to calculate the reply address nowadays.
315 StrBufAppendBufPlain(sc->ListID, HKEY(">"), 0);
317 if (StrLength(sc->Users[roommailalias]) == 0)
319 sc->Users[roommailalias] = NewStrBuf();
321 StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("room_"), 0);
322 StrBufAppendBuf(sc->Users[roommailalias], RoomName, 0);
323 StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("@"), 0);
324 StrBufAppendBufPlain(sc->Users[roommailalias], config.c_fqdn, -1, 0);
326 StrBufLowerCase(sc->Users[roommailalias]);
329 FreeStrBuf(&RoomName);
334 * Batch up and send all outbound traffic from the current room
336 void network_spoolout_room(SpoolControl *sc)
338 struct CitContext *CCC = CC;
344 * If the room doesn't exist, don't try to perform its networking tasks.
345 * Normally this should never happen, but once in a while maybe a room gets
346 * queued for networking and then deleted before it can happen.
348 memcpy (&CCC->room, &sc->room, sizeof(ctdlroom));
350 syslog(LOG_INFO, "Networking started for <%s>\n", CCC->room.QRname);
352 /* If there are digest recipients, we have to build a digest */
353 if (sc->Users[digestrecp] != NULL) {
354 sc->digestfp = tmpfile();
355 fprintf(sc->digestfp, "Content-type: text/plain\n\n");
360 /* remember where we started... */
361 lastsent = sc->lastsent;
363 /* Do something useful */
364 CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL,
365 network_spool_msg, sc);
367 /* If we wrote a digest, deliver it and then close it */
368 if (StrLength(sc->Users[roommailalias]) > 0)
371 len = StrLength(sc->Users[roommailalias]);
372 if (len + 1 > sizeof(buf))
373 len = sizeof(buf) - 1;
374 memcpy(buf, ChrPtr(sc->Users[roommailalias]), len);
379 snprintf(buf, sizeof buf, "room_%s@%s",
380 CCC->room.QRname, config.c_fqdn);
383 for (i=0; buf[i]; ++i) {
384 buf[i] = tolower(buf[i]);
385 if (isspace(buf[i])) buf[i] = '_';
387 if (sc->digestfp != NULL) {
388 fprintf(sc->digestfp,
389 " -----------------------------------"
390 "------------------------------------"
392 "You are subscribed to the '%s' "
394 "To post to the list: %s\n",
395 CCC->room.QRname, buf
397 network_deliver_digest(sc); /* deliver and close */
400 /* Now rewrite the config file */
401 if (sc->lastsent != lastsent)
403 sc->RNCfg = CtdlGetNetCfgForRoom(sc->room.QRnumber);
405 sc->RNCfg->lastsent = sc->lastsent;
406 sc->RNCfg->changed = 1;
408 end_critical_section(S_NETCONFIGS);
412 * Process a buffer containing a single message from a single file
413 * from the inbound queue
415 void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
418 struct CitContext *CCC = CC;
420 struct CtdlMessage *msg = NULL;
423 recptypes *recp = NULL;
424 char target_room[ROOMNAMELEN];
425 struct ser_ret sermsg;
426 char filename[PATH_MAX];
428 const StrBuf *nexthop = NULL;
429 unsigned char firstbyte;
430 unsigned char lastbyte;
432 QN_syslog(LOG_DEBUG, "network_process_buffer() processing %ld bytes\n", size);
434 /* Validate just a little bit. First byte should be FF and * last byte should be 00. */
435 firstbyte = buffer[0];
436 lastbyte = buffer[size-1];
437 if ( (firstbyte != 255) || (lastbyte != 0) ) {
438 QN_syslog(LOG_ERR, "Corrupt message ignored. Length=%ld, firstbyte = %d, lastbyte = %d\n",
439 size, firstbyte, lastbyte);
443 /* Set default target room to trash */
444 strcpy(target_room, TWITROOM);
446 /* Load the message into memory */
447 msg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
448 memset(msg, 0, sizeof(struct CtdlMessage));
449 msg->cm_magic = CTDLMESSAGE_MAGIC;
450 msg->cm_anon_type = buffer[1];
451 msg->cm_format_type = buffer[2];
453 for (pos = 3; pos < size; ++pos) {
455 len = strlen(buffer + pos + 1);
456 CM_SetField(msg, field, buffer + pos + 1, len);
460 /* Check for message routing */
461 if (!CM_IsEmpty(msg, eDestination)) {
462 if (strcasecmp(msg->cm_fields[eDestination], config.c_nodename)) {
464 /* route the message */
465 Buf = NewStrBufPlain(CM_KEY(msg,eDestination));
466 if (CtdlIsValidNode(&nexthop,
472 Netmap_AddMe(msg, HKEY("unknown_user"));
474 /* serialize the message */
475 CtdlSerializeMessage(&sermsg, msg);
478 if (StrLength(nexthop) == 0) {
489 QN_syslog(LOG_DEBUG, "Appending to %s\n", filename);
490 fp = fopen(filename, "ab");
492 fwrite(sermsg.ser, sermsg.len, 1, fp);
496 QN_syslog(LOG_ERR, "%s: %s\n", filename, strerror(errno));
504 else { /* invalid destination node name */
508 "A message you sent could not be delivered due to an invalid destination node"
509 " name. Please check the address and try sending the message again.\n");
518 * Check to see if we already have a copy of this message, and
519 * abort its processing if so. (We used to post a warning to Aide>
520 * every time this happened, but the network is now so densely
521 * connected that it's inevitable.)
523 if (network_usetable(msg) != 0) {
528 /* Learn network topology from the path */
529 if (!CM_IsEmpty(msg, eNodeName) && !CM_IsEmpty(msg, eMessagePath)) {
530 NetworkLearnTopology(msg->cm_fields[eNodeName],
531 msg->cm_fields[eMessagePath],
536 /* Is the sending node giving us a very persuasive suggestion about
537 * which room this message should be saved in? If so, go with that.
539 if (!CM_IsEmpty(msg, eRemoteRoom)) {
540 safestrncpy(target_room, msg->cm_fields[eRemoteRoom], sizeof target_room);
543 /* Otherwise, does it have a recipient? If so, validate it... */
544 else if (!CM_IsEmpty(msg, eRecipient)) {
545 recp = validate_recipients(msg->cm_fields[eRecipient], NULL, 0);
546 if (recp != NULL) if (recp->num_error != 0) {
548 "A message you sent could not be delivered due to an invalid address.\n"
549 "Please check the address and try sending the message again.\n");
551 free_recipients(recp);
552 QNM_syslog(LOG_DEBUG, "Bouncing message due to invalid recipient address.\n");
555 strcpy(target_room, ""); /* no target room if mail */
558 /* Our last shot at finding a home for this message is to see if
559 * it has the eOriginalRoom (O) field (Originating room) set.
561 else if (!CM_IsEmpty(msg, eOriginalRoom)) {
562 safestrncpy(target_room, msg->cm_fields[eOriginalRoom], sizeof target_room);
565 /* Strip out fields that are only relevant during transit */
566 CM_FlushField(msg, eDestination);
567 CM_FlushField(msg, eRemoteRoom);
569 /* save the message into a room */
570 if (PerformNetprocHooks(msg, target_room) == 0) {
571 msg->cm_flags = CM_SKIP_HOOKS;
572 CtdlSubmitMsg(msg, recp, target_room, 0);
575 free_recipients(recp);
580 * Process a single message from a single file from the inbound queue
582 void network_process_message(FILE *fp,
585 HashList *working_ignetcfg,
586 HashList *the_netmap,
593 hold_pos = ftell(fp);
594 size = msgend - msgstart + 1;
595 buffer = malloc(size);
596 if (buffer != NULL) {
597 fseek(fp, msgstart, SEEK_SET);
598 if (fread(buffer, size, 1, fp) > 0) {
599 network_process_buffer(buffer,
608 fseek(fp, hold_pos, SEEK_SET);
613 * Process a single file from the inbound queue
615 void network_process_file(char *filename,
616 HashList *working_ignetcfg,
617 HashList *the_netmap,
620 struct CitContext *CCC = CC;
622 long msgstart = (-1L);
628 fp = fopen(filename, "rb");
630 QN_syslog(LOG_CRIT, "Error opening %s: %s\n", filename, strerror(errno));
634 fseek(fp, 0L, SEEK_END);
635 QN_syslog(LOG_INFO, "network: processing %ld bytes from %s\n", ftell(fp), filename);
638 /* Look for messages in the data stream and break them out */
639 while (ch = getc(fp), ch >= 0) {
642 if (msgstart >= 0L) {
644 network_process_message(fp,
659 if (msgstart >= 0L) {
660 network_process_message(fp,
671 "network: processed %d messages in %s\n",
681 * Process anything in the inbound queue
683 void network_do_spoolin(HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
685 struct CitContext *CCC = CC;
688 struct dirent *filedir_entry;
690 char filename[PATH_MAX];
691 static time_t last_spoolin_mtime = 0L;
696 * Check the spoolin directory's modification time. If it hasn't
697 * been touched, we don't need to scan it.
699 if (stat(ctdl_netin_dir, &statbuf)) return;
700 if (statbuf.st_mtime == last_spoolin_mtime) {
701 QNM_syslog(LOG_DEBUG, "network: nothing in inbound queue\n");
704 last_spoolin_mtime = statbuf.st_mtime;
705 QNM_syslog(LOG_DEBUG, "network: processing inbound queue\n");
708 * Ok, there's something interesting in there, so scan it.
710 dp = opendir(ctdl_netin_dir);
711 if (dp == NULL) return;
713 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
719 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
720 (filedir_entry != NULL))
722 #ifdef _DIRENT_HAVE_D_NAMLEN
723 d_namelen = filedir_entry->d_namlen;
726 d_namelen = strlen(filedir_entry->d_name);
729 #ifdef _DIRENT_HAVE_D_TYPE
730 d_type = filedir_entry->d_type;
734 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
735 continue; /* Ignore backup files... */
737 if ((d_namelen == 1) &&
738 (filedir_entry->d_name[0] == '.'))
741 if ((d_namelen == 2) &&
742 (filedir_entry->d_name[0] == '.') &&
743 (filedir_entry->d_name[1] == '.'))
746 if (d_type == DT_UNKNOWN) {
754 filedir_entry->d_name);
756 if (lstat(path, &s) == 0) {
757 d_type = IFTODT(s.st_mode);
765 case DT_LNK: /* TODO: check whether its a file or a directory */
773 network_process_file(filename,
785 * Step 1: consolidate files in the outbound queue into one file per neighbor node
786 * Step 2: delete any files in the outbound queue that were for neighbors who no longer exist.
788 void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netmap)
790 struct CitContext *CCC = CC;
796 struct dirent *filedir_entry;
798 char spooloutfilename[PATH_MAX];
799 char filename[PATH_MAX];
800 const StrBuf *nexthop;
808 /* Step 1: consolidate files in the outbound queue into one file per neighbor node */
809 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
810 if (d == NULL) return;
812 dp = opendir(ctdl_netout_dir);
818 NextHop = NewStrBuf();
819 memset(&IOB, 0, sizeof(IOBuffer));
820 memset(&FDIO, 0, sizeof(FDIOBuffer));
823 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
824 (filedir_entry != NULL))
826 #ifdef _DIRENT_HAVE_D_NAMLEN
827 d_namelen = filedir_entry->d_namlen;
830 d_namelen = strlen(filedir_entry->d_name);
833 #ifdef _DIRENT_HAVE_D_TYPE
834 d_type = filedir_entry->d_type;
838 if (d_type == DT_DIR)
841 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
842 continue; /* Ignore backup files... */
844 if ((d_namelen == 1) &&
845 (filedir_entry->d_name[0] == '.'))
848 if ((d_namelen == 2) &&
849 (filedir_entry->d_name[0] == '.') &&
850 (filedir_entry->d_name[1] == '.'))
853 pch = strchr(filedir_entry->d_name, '@');
861 filedir_entry->d_name);
864 filedir_entry->d_name,
865 pch - filedir_entry->d_name);
867 snprintf(spooloutfilename,
868 sizeof spooloutfilename,
873 QN_syslog(LOG_DEBUG, "Consolidate %s to %s\n", filename, ChrPtr(NextHop));
874 if (CtdlNetworkTalkingTo(SKEY(NextHop), NTT_CHECK)) {
877 "Currently online with %s - skipping for now\n",
885 const char *err = NULL;
886 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_ADD);
888 infd = open(filename, O_RDONLY);
892 "failed to open %s for reading due to %s; skipping.\n",
893 filename, strerror(errno)
895 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
899 outfd = open(spooloutfilename,
900 O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY,
904 outfd = open(spooloutfilename,
905 O_EXCL|O_NONBLOCK|O_WRONLY,
911 "failed to open %s for reading due to %s; skipping.\n",
912 spooloutfilename, strerror(errno)
915 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
919 dsize = lseek(outfd, 0, SEEK_END);
920 lseek(outfd, -dsize, SEEK_SET);
922 fstat(infd, &statbuf);
923 fsize = statbuf.st_size;
925 fsize = lseek(infd, 0, SEEK_END);
928 FDIOBufferInit(&FDIO, &IOB, outfd, fsize + dsize);
929 FDIO.ChunkSendRemain = fsize;
930 FDIO.TotalSentAlready = dsize;
933 do {} while ((FileMoveChunked(&FDIO, &err) > 0) && (err == NULL));
937 "Spoolfile %s now "SIZE_T_FMT" k\n",
945 "failed to append to %s [%s]; rolling back..\n",
946 spooloutfilename, strerror(errno)
948 /* whoops partial append?? truncate spooloutfilename again! */
949 ftruncate(outfd, dsize);
951 FDIOBufferDelete(&FDIO);
954 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
960 FreeStrBuf(&NextHop);
962 "skipping Spoolcleanup because of %d files unprocessed.\n",
969 /* Step 2: delete any files in the outbound queue that were for neighbors who no longer exist */
970 dp = opendir(ctdl_netout_dir);
972 FreeStrBuf(&NextHop);
977 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
978 (filedir_entry != NULL))
980 #ifdef _DIRENT_HAVE_D_NAMLEN
981 d_namelen = filedir_entry->d_namlen;
984 d_namelen = strlen(filedir_entry->d_name);
987 #ifdef _DIRENT_HAVE_D_TYPE
988 d_type = filedir_entry->d_type;
992 if (d_type == DT_DIR)
995 if ((d_namelen == 1) &&
996 (filedir_entry->d_name[0] == '.'))
999 if ((d_namelen == 2) &&
1000 (filedir_entry->d_name[0] == '.') &&
1001 (filedir_entry->d_name[1] == '.'))
1004 pch = strchr(filedir_entry->d_name, '@');
1005 if (pch == NULL) /* no @ in name? consolidated file. */
1008 StrBufPlain(NextHop,
1009 filedir_entry->d_name,
1010 pch - filedir_entry->d_name);
1016 filedir_entry->d_name
1019 i = CtdlIsValidNode(&nexthop,
1025 if ( (i != 0) || (StrLength(nexthop) > 0) ) {
1029 FreeStrBuf(&NextHop);
1034 void free_spoolcontrol_struct(SpoolControl **sc)
1036 free_spoolcontrol_struct_members(*sc);
1041 void free_spoolcontrol_struct_members(SpoolControl *sc)
1044 FreeStrBuf(&sc->RoomInfo);
1045 FreeStrBuf(&sc->ListID);
1046 for (i = 0; i < maxRoomNetCfg; i++)
1047 FreeStrBuf(&sc->Users[i]);
1053 * It's ok if these directories already exist. Just fail silently.
1055 void create_spool_dirs(void) {
1056 if ((mkdir(ctdl_spool_dir, 0700) != 0) && (errno != EEXIST))
1057 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_spool_dir, strerror(errno));
1058 if (chown(ctdl_spool_dir, CTDLUID, (-1)) != 0)
1059 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_spool_dir, strerror(errno));
1060 if ((mkdir(ctdl_netin_dir, 0700) != 0) && (errno != EEXIST))
1061 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_netin_dir, strerror(errno));
1062 if (chown(ctdl_netin_dir, CTDLUID, (-1)) != 0)
1063 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netin_dir, strerror(errno));
1064 if ((mkdir(ctdl_nettmp_dir, 0700) != 0) && (errno != EEXIST))
1065 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_nettmp_dir, strerror(errno));
1066 if (chown(ctdl_nettmp_dir, CTDLUID, (-1)) != 0)
1067 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_nettmp_dir, strerror(errno));
1068 if ((mkdir(ctdl_netout_dir, 0700) != 0) && (errno != EEXIST))
1069 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_netout_dir, strerror(errno));
1070 if (chown(ctdl_netout_dir, CTDLUID, (-1)) != 0)
1071 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netout_dir, strerror(errno));
1075 * Module entry point
1077 CTDL_MODULE_INIT(network_spool)
1081 CtdlREGISTERRoomCfgType(subpending, ParseSubPendingLine, 0, 5, SerializeGeneric, DeleteGenericCfgLine); /// todo: move this to mailinglist manager
1082 CtdlREGISTERRoomCfgType(unsubpending, ParseUnSubPendingLine, 0, 4, SerializeGeneric, DeleteGenericCfgLine); /// todo: move this to mailinglist manager
1083 CtdlREGISTERRoomCfgType(lastsent, ParseLastSent, 1, 1, SerializeLastSent, DeleteLastSent);
1084 CtdlREGISTERRoomCfgType(ignet_push_share, ParseGeneric, 0, 2, SerializeGeneric, DeleteGenericCfgLine); // [remotenode|remoteroomname (optional)]// todo: move this to the ignet client
1085 CtdlREGISTERRoomCfgType(listrecp, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1086 CtdlREGISTERRoomCfgType(digestrecp, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1087 CtdlREGISTERRoomCfgType(participate, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1088 CtdlREGISTERRoomCfgType(roommailalias, ParseRoomAlias, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1090 create_spool_dirs();
1091 //////todo CtdlRegisterCleanupHook(destroy_network_queue_room);
1093 return "network_spool";