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"
76 #include "citadel_dirs.h"
80 #include "ctdl_module.h"
92 #define IFTODT(mode) (((mode) & 0170000) >> 12)
93 #define DTTOIF(dirtype) ((dirtype) << 12)
97 void ParseLastSent(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
100 nptr = (RoomNetCfgLine *)
101 malloc(sizeof(RoomNetCfgLine));
102 memset(nptr, 0, sizeof(RoomNetCfgLine));
103 OneRNCFG->lastsent = extract_long(LinePos, 0);
104 OneRNCFG->NetConfigs[ThisOne->C] = nptr;
107 void ParseRoomAlias(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *rncfg)
109 if (rncfg->Sender != NULL)
112 ParseGeneric(ThisOne, Line, LinePos, rncfg);
113 rncfg->Sender = NewStrBufDup(rncfg->NetConfigs[roommailalias]->Value[0]);
116 void ParseSubPendingLine(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
118 if (time(NULL) - extract_long(LinePos, 3) > EXP)
119 return; /* expired subscription... */
121 ParseGeneric(ThisOne, Line, LinePos, OneRNCFG);
123 void ParseUnSubPendingLine(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
125 if (time(NULL) - extract_long(LinePos, 2) > EXP)
126 return; /* expired subscription... */
128 ParseGeneric(ThisOne, Line, LinePos, OneRNCFG);
132 void SerializeLastSent(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *RNCfg, RoomNetCfgLine *data)
134 StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
135 StrBufAppendPrintf(OutputBuffer, "|%ld\n", RNCfg->lastsent);
138 void DeleteLastSent(const CfgLineType *ThisOne, RoomNetCfgLine **data)
144 static const RoomNetCfg SpoolCfgs [4] = {
151 static const long SpoolCfgsCopyN [4] = {
155 int HaveSpoolConfig(OneRoomNetCfg* RNCfg)
159 for (i=0; i < 4; i++) if (RNCfg->NetConfigs[SpoolCfgs[i]] == NULL) interested = 1;
165 void InspectQueuedRoom(SpoolControl **pSC,
166 RoomProcList *room_to_spool,
167 HashList *working_ignetcfg,
168 HashList *the_netmap)
173 sc = (SpoolControl*)malloc(sizeof(SpoolControl));
174 memset(sc, 0, sizeof(SpoolControl));
175 sc->RNCfg = room_to_spool->OneRNCfg;
176 sc->lastsent = room_to_spool->lastsent;
177 sc->working_ignetcfg = working_ignetcfg;
178 sc->the_netmap = the_netmap;
181 * If the room doesn't exist, don't try to perform its networking tasks.
182 * Normally this should never happen, but once in a while maybe a room gets
183 * queued for networking and then deleted before it can happen.
185 if (CtdlGetRoom(&sc->room, room_to_spool->name) != 0) {
186 syslog(LOG_CRIT, "ERROR: cannot load <%s>\n", room_to_spool->name);
190 if (sc->room.QRhighest <= sc->lastsent)
192 syslog(LOG_DEBUG, "nothing to do for <%s>\n", room_to_spool->name);
197 if (sc->RNCfg == NULL)
198 sc->RNCfg = CtdlGetNetCfgForRoom(sc->room.QRnumber);
200 if (!HaveSpoolConfig(sc->RNCfg))
203 /* nothing to do for this room... */
207 /* Now lets remember whats needed for the actual work... */
209 for (i=0; i < 4; i++)
211 aggregate_recipients(&sc->Users[SpoolCfgs[i]],
217 if (StrLength(sc->RNCfg->Sender) > 0)
218 sc->Users[roommailalias] = NewStrBufDup(sc->RNCfg->Sender);
225 void CalcListID(SpoolControl *sc)
230 struct CitContext *CCC = CC;
231 char filename[PATH_MAX];
232 #define MAX_LISTIDLENGTH 150
234 assoc_file_name(filename, sizeof filename, &sc->room, ctdl_info_dir);
235 fd = open(filename, 0);
240 if ((fstat(fd, &stbuf) == 0) &&
243 sc->RoomInfo = NewStrBufPlain(NULL, stbuf.st_size + 1);
244 StrBufReadBLOB(sc->RoomInfo, &fd, 0, stbuf.st_size, &err);
249 sc->ListID = NewStrBufPlain(NULL, 1024);
250 if (StrLength(sc->RoomInfo) > 0)
252 const char *Pos = NULL;
253 StrBufSipLine(sc->ListID, sc->RoomInfo, &Pos);
255 if (StrLength(sc->ListID) > MAX_LISTIDLENGTH)
257 StrBufCutAt(sc->ListID, MAX_LISTIDLENGTH, NULL);
258 StrBufAppendBufPlain(sc->ListID, HKEY("..."), 0);
260 StrBufAsciify(sc->ListID, ' ');
264 StrBufAppendBufPlain(sc->ListID, CCC->room.QRname, -1, 0);
267 StrBufAppendBufPlain(sc->ListID, HKEY("<"), 0);
268 RoomName = NewStrBufPlain (sc->room.QRname, -1);
269 StrBufAsciify(RoomName, '_');
270 StrBufReplaceChars(RoomName, ' ', '_');
272 if (StrLength(sc->Users[roommailalias]) > 0)
277 Pos = StrLength(sc->ListID);
278 StrBufAppendBuf(sc->ListID, sc->Users[roommailalias], 0);
279 AtPos = strchr(ChrPtr(sc->ListID) + Pos, '@');
283 StrBufPeek(sc->ListID, AtPos, 0, '.');
288 StrBufAppendBufPlain(sc->ListID, HKEY("room_"), 0);
289 StrBufAppendBuf(sc->ListID, RoomName, 0);
290 StrBufAppendBufPlain(sc->ListID, HKEY("."), 0);
291 StrBufAppendBufPlain(sc->ListID, config.c_fqdn, -1, 0);
294 * roomname <Room-Number.list-id.fqdn>
295 * according to rfc2919.txt it only has to be a uniq identifier
296 * under the domain of the system;
297 * in general MUAs use it to calculate the reply address nowadays.
300 StrBufAppendBufPlain(sc->ListID, HKEY(">"), 0);
302 if (StrLength(sc->Users[roommailalias]) == 0)
304 sc->Users[roommailalias] = NewStrBuf();
306 StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("room_"), 0);
307 StrBufAppendBuf(sc->Users[roommailalias], RoomName, 0);
308 StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("@"), 0);
309 StrBufAppendBufPlain(sc->Users[roommailalias], config.c_fqdn, -1, 0);
311 StrBufLowerCase(sc->Users[roommailalias]);
314 FreeStrBuf(&RoomName);
319 * Batch up and send all outbound traffic from the current room
321 void network_spoolout_room(SpoolControl *sc)
323 struct CitContext *CCC = CC;
329 * If the room doesn't exist, don't try to perform its networking tasks.
330 * Normally this should never happen, but once in a while maybe a room gets
331 * queued for networking and then deleted before it can happen.
333 memcpy (&CCC->room, &sc->room, sizeof(ctdlroom));
335 syslog(LOG_INFO, "Networking started for <%s>\n", CCC->room.QRname);
337 /* If there are digest recipients, we have to build a digest */
338 if (sc->Users[digestrecp] != NULL) {
339 sc->digestfp = tmpfile();
340 fprintf(sc->digestfp, "Content-type: text/plain\n\n");
345 /* remember where we started... */
346 lastsent = sc->lastsent;
348 /* Do something useful */
349 CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL,
350 network_spool_msg, sc);
352 /* If we wrote a digest, deliver it and then close it */
353 if (StrLength(sc->Users[roommailalias]) > 0)
356 len = StrLength(sc->Users[roommailalias]);
357 if (len + 1 > sizeof(buf))
358 len = sizeof(buf) - 1;
359 memcpy(buf, ChrPtr(sc->Users[roommailalias]), len);
364 snprintf(buf, sizeof buf, "room_%s@%s",
365 CCC->room.QRname, config.c_fqdn);
368 for (i=0; buf[i]; ++i) {
369 buf[i] = tolower(buf[i]);
370 if (isspace(buf[i])) buf[i] = '_';
372 if (sc->digestfp != NULL) {
373 fprintf(sc->digestfp,
374 " -----------------------------------"
375 "------------------------------------"
377 "You are subscribed to the '%s' "
379 "To post to the list: %s\n",
380 CCC->room.QRname, buf
382 network_deliver_digest(sc); /* deliver and close */
385 /* Now rewrite the config file */
386 if (sc->lastsent != lastsent)
388 sc->RNCfg = CtdlGetNetCfgForRoom(sc->room.QRnumber);
390 sc->RNCfg->lastsent = sc->lastsent;
391 sc->RNCfg->changed = 1;
393 end_critical_section(S_NETCONFIGS);
397 * Process a buffer containing a single message from a single file
398 * from the inbound queue
400 void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
403 struct CitContext *CCC = CC;
405 struct CtdlMessage *msg = NULL;
408 struct recptypes *recp = NULL;
409 char target_room[ROOMNAMELEN];
410 struct ser_ret sermsg;
411 char *oldpath = NULL;
412 char filename[PATH_MAX];
414 const StrBuf *nexthop = NULL;
415 unsigned char firstbyte;
416 unsigned char lastbyte;
418 QN_syslog(LOG_DEBUG, "network_process_buffer() processing %ld bytes\n", size);
420 /* Validate just a little bit. First byte should be FF and * last byte should be 00. */
421 firstbyte = buffer[0];
422 lastbyte = buffer[size-1];
423 if ( (firstbyte != 255) || (lastbyte != 0) ) {
424 QN_syslog(LOG_ERR, "Corrupt message ignored. Length=%ld, firstbyte = %d, lastbyte = %d\n",
425 size, firstbyte, lastbyte);
429 /* Set default target room to trash */
430 strcpy(target_room, TWITROOM);
432 /* Load the message into memory */
433 msg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
434 memset(msg, 0, sizeof(struct CtdlMessage));
435 msg->cm_magic = CTDLMESSAGE_MAGIC;
436 msg->cm_anon_type = buffer[1];
437 msg->cm_format_type = buffer[2];
439 for (pos = 3; pos < size; ++pos) {
441 len = strlen(buffer + pos + 1);
442 msg->cm_fields[field] = malloc(len + 1);
443 memcpy (msg->cm_fields[field], buffer+ pos + 1, len + 1);
447 /* Check for message routing */
448 if (msg->cm_fields['D'] != NULL) {
449 if (strcasecmp(msg->cm_fields['D'], config.c_nodename)) {
451 /* route the message */
452 Buf = NewStrBufPlain(msg->cm_fields['D'], -1);
453 if (CtdlIsValidNode(&nexthop,
459 /* prepend our node to the path */
460 if (msg->cm_fields['P'] != NULL) {
461 oldpath = msg->cm_fields['P'];
462 msg->cm_fields['P'] = NULL;
465 oldpath = strdup("unknown_user");
467 size = strlen(oldpath) + SIZ;
468 msg->cm_fields['P'] = malloc(size);
469 snprintf(msg->cm_fields['P'], size, "%s!%s",
470 config.c_nodename, oldpath);
473 /* serialize the message */
474 serialize_message(&sermsg, msg);
477 if (StrLength(nexthop) == 0) {
488 QN_syslog(LOG_DEBUG, "Appending to %s\n", filename);
489 fp = fopen(filename, "ab");
491 fwrite(sermsg.ser, sermsg.len, 1, fp);
495 QN_syslog(LOG_ERR, "%s: %s\n", filename, strerror(errno));
498 CtdlFreeMessage(msg);
503 else { /* invalid destination node name */
507 "A message you sent could not be delivered due to an invalid destination node"
508 " name. Please check the address and try sending the message again.\n");
517 * Check to see if we already have a copy of this message, and
518 * abort its processing if so. (We used to post a warning to Aide>
519 * every time this happened, but the network is now so densely
520 * connected that it's inevitable.)
522 if (network_usetable(msg) != 0) {
523 CtdlFreeMessage(msg);
527 /* Learn network topology from the path */
528 if ((msg->cm_fields['N'] != NULL) && (msg->cm_fields['P'] != NULL)) {
529 NetworkLearnTopology(msg->cm_fields['N'],
535 /* Is the sending node giving us a very persuasive suggestion about
536 * which room this message should be saved in? If so, go with that.
538 if (msg->cm_fields['C'] != NULL) {
539 safestrncpy(target_room, msg->cm_fields['C'], sizeof target_room);
542 /* Otherwise, does it have a recipient? If so, validate it... */
543 else if (msg->cm_fields['R'] != NULL) {
544 recp = validate_recipients(msg->cm_fields['R'], NULL, 0);
545 if (recp != NULL) if (recp->num_error != 0) {
547 "A message you sent could not be delivered due to an invalid address.\n"
548 "Please check the address and try sending the message again.\n");
550 free_recipients(recp);
551 QNM_syslog(LOG_DEBUG, "Bouncing message due to invalid recipient address.\n");
554 strcpy(target_room, ""); /* no target room if mail */
557 /* Our last shot at finding a home for this message is to see if
558 * it has the O field (Originating room) set.
560 else if (msg->cm_fields['O'] != NULL) {
561 safestrncpy(target_room, msg->cm_fields['O'], sizeof target_room);
564 /* Strip out fields that are only relevant during transit */
565 if (msg->cm_fields['D'] != NULL) {
566 free(msg->cm_fields['D']);
567 msg->cm_fields['D'] = NULL;
569 if (msg->cm_fields['C'] != NULL) {
570 free(msg->cm_fields['C']);
571 msg->cm_fields['C'] = NULL;
574 /* save the message into a room */
575 if (PerformNetprocHooks(msg, target_room) == 0) {
576 msg->cm_flags = CM_SKIP_HOOKS;
577 CtdlSubmitMsg(msg, recp, target_room, 0);
579 CtdlFreeMessage(msg);
580 free_recipients(recp);
585 * Process a single message from a single file from the inbound queue
587 void network_process_message(FILE *fp,
590 HashList *working_ignetcfg,
591 HashList *the_netmap,
598 hold_pos = ftell(fp);
599 size = msgend - msgstart + 1;
600 buffer = malloc(size);
601 if (buffer != NULL) {
602 fseek(fp, msgstart, SEEK_SET);
603 if (fread(buffer, size, 1, fp) > 0) {
604 network_process_buffer(buffer,
613 fseek(fp, hold_pos, SEEK_SET);
618 * Process a single file from the inbound queue
620 void network_process_file(char *filename,
621 HashList *working_ignetcfg,
622 HashList *the_netmap,
625 struct CitContext *CCC = CC;
627 long msgstart = (-1L);
633 fp = fopen(filename, "rb");
635 QN_syslog(LOG_CRIT, "Error opening %s: %s\n", filename, strerror(errno));
639 fseek(fp, 0L, SEEK_END);
640 QN_syslog(LOG_INFO, "network: processing %ld bytes from %s\n", ftell(fp), filename);
643 /* Look for messages in the data stream and break them out */
644 while (ch = getc(fp), ch >= 0) {
647 if (msgstart >= 0L) {
649 network_process_message(fp,
664 if (msgstart >= 0L) {
665 network_process_message(fp,
676 "network: processed %d messages in %s\n",
686 * Process anything in the inbound queue
688 void network_do_spoolin(HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
690 struct CitContext *CCC = CC;
693 struct dirent *filedir_entry;
695 char filename[PATH_MAX];
696 static time_t last_spoolin_mtime = 0L;
701 * Check the spoolin directory's modification time. If it hasn't
702 * been touched, we don't need to scan it.
704 if (stat(ctdl_netin_dir, &statbuf)) return;
705 if (statbuf.st_mtime == last_spoolin_mtime) {
706 QNM_syslog(LOG_DEBUG, "network: nothing in inbound queue\n");
709 last_spoolin_mtime = statbuf.st_mtime;
710 QNM_syslog(LOG_DEBUG, "network: processing inbound queue\n");
713 * Ok, there's something interesting in there, so scan it.
715 dp = opendir(ctdl_netin_dir);
716 if (dp == NULL) return;
718 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
724 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
725 (filedir_entry != NULL))
727 #ifdef _DIRENT_HAVE_D_NAMLEN
728 d_namelen = filedir_entry->d_namelen;
731 d_namelen = strlen(filedir_entry->d_name);
734 #ifdef _DIRENT_HAVE_D_TYPE
735 d_type = filedir_entry->d_type;
739 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
740 continue; /* Ignore backup files... */
742 if ((d_namelen == 1) &&
743 (filedir_entry->d_name[0] == '.'))
746 if ((d_namelen == 2) &&
747 (filedir_entry->d_name[0] == '.') &&
748 (filedir_entry->d_name[1] == '.'))
751 if (d_type == DT_UNKNOWN) {
759 filedir_entry->d_name);
761 if (lstat(path, &s) == 0) {
762 d_type = IFTODT(s.st_mode);
770 case DT_LNK: /* TODO: check whether its a file or a directory */
778 network_process_file(filename,
790 * Step 1: consolidate files in the outbound queue into one file per neighbor node
791 * Step 2: delete any files in the outbound queue that were for neighbors who no longer exist.
793 void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netmap)
795 struct CitContext *CCC = CC;
801 struct dirent *filedir_entry;
803 char spooloutfilename[PATH_MAX];
804 char filename[PATH_MAX];
805 const StrBuf *nexthop;
813 /* Step 1: consolidate files in the outbound queue into one file per neighbor node */
814 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
815 if (d == NULL) return;
817 dp = opendir(ctdl_netout_dir);
823 NextHop = NewStrBuf();
824 memset(&IOB, 0, sizeof(IOBuffer));
825 memset(&FDIO, 0, sizeof(FDIOBuffer));
828 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
829 (filedir_entry != NULL))
831 #ifdef _DIRENT_HAVE_D_NAMLEN
832 d_namelen = filedir_entry->d_namelen;
835 d_namelen = strlen(filedir_entry->d_name);
838 #ifdef _DIRENT_HAVE_D_TYPE
839 d_type = filedir_entry->d_type;
843 if (d_type == DT_DIR)
846 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
847 continue; /* Ignore backup files... */
849 if ((d_namelen == 1) &&
850 (filedir_entry->d_name[0] == '.'))
853 if ((d_namelen == 2) &&
854 (filedir_entry->d_name[0] == '.') &&
855 (filedir_entry->d_name[1] == '.'))
858 pch = strchr(filedir_entry->d_name, '@');
866 filedir_entry->d_name);
869 filedir_entry->d_name,
870 pch - filedir_entry->d_name);
872 snprintf(spooloutfilename,
873 sizeof spooloutfilename,
878 QN_syslog(LOG_DEBUG, "Consolidate %s to %s\n", filename, ChrPtr(NextHop));
879 if (CtdlNetworkTalkingTo(SKEY(NextHop), NTT_CHECK)) {
882 "Currently online with %s - skipping for now\n",
890 const char *err = NULL;
891 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_ADD);
893 infd = open(filename, O_RDONLY);
897 "failed to open %s for reading due to %s; skipping.\n",
898 filename, strerror(errno)
900 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
904 outfd = open(spooloutfilename,
905 O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY,
909 outfd = open(spooloutfilename,
910 O_EXCL|O_NONBLOCK|O_WRONLY,
916 "failed to open %s for reading due to %s; skipping.\n",
917 spooloutfilename, strerror(errno)
920 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
924 dsize = lseek(outfd, 0, SEEK_END);
925 lseek(outfd, -dsize, SEEK_SET);
927 fstat(infd, &statbuf);
928 fsize = statbuf.st_size;
930 fsize = lseek(infd, 0, SEEK_END);
933 FDIOBufferInit(&FDIO, &IOB, outfd, fsize + dsize);
934 FDIO.ChunkSendRemain = fsize;
935 FDIO.TotalSentAlready = dsize;
938 do {} while ((FileMoveChunked(&FDIO, &err) > 0) && (err == NULL));
942 "Spoolfile %s now "SIZE_T_FMT" k\n",
950 "failed to append to %s [%s]; rolling back..\n",
951 spooloutfilename, strerror(errno)
953 /* whoops partial append?? truncate spooloutfilename again! */
954 ftruncate(outfd, dsize);
956 FDIOBufferDelete(&FDIO);
959 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
965 FreeStrBuf(&NextHop);
967 "skipping Spoolcleanup because of %d files unprocessed.\n",
974 /* Step 2: delete any files in the outbound queue that were for neighbors who no longer exist */
975 dp = opendir(ctdl_netout_dir);
977 FreeStrBuf(&NextHop);
982 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
983 (filedir_entry != NULL))
985 #ifdef _DIRENT_HAVE_D_NAMLEN
986 d_namelen = filedir_entry->d_namelen;
989 d_namelen = strlen(filedir_entry->d_name);
992 #ifdef _DIRENT_HAVE_D_TYPE
993 d_type = filedir_entry->d_type;
997 if (d_type == DT_DIR)
1000 if ((d_namelen == 1) &&
1001 (filedir_entry->d_name[0] == '.'))
1004 if ((d_namelen == 2) &&
1005 (filedir_entry->d_name[0] == '.') &&
1006 (filedir_entry->d_name[1] == '.'))
1009 pch = strchr(filedir_entry->d_name, '@');
1010 if (pch == NULL) /* no @ in name? consolidated file. */
1013 StrBufPlain(NextHop,
1014 filedir_entry->d_name,
1015 pch - filedir_entry->d_name);
1021 filedir_entry->d_name
1024 i = CtdlIsValidNode(&nexthop,
1030 if ( (i != 0) || (StrLength(nexthop) > 0) ) {
1034 FreeStrBuf(&NextHop);
1039 void free_spoolcontrol_struct(SpoolControl **sc)
1041 free_spoolcontrol_struct_members(*sc);
1046 void free_spoolcontrol_struct_members(SpoolControl *sc)
1049 FreeStrBuf(&sc->RoomInfo);
1050 FreeStrBuf(&sc->ListID);
1051 for (i = 0; i < maxRoomNetCfg; i++)
1052 FreeStrBuf(&sc->Users[i]);
1058 * It's ok if these directories already exist. Just fail silently.
1060 void create_spool_dirs(void) {
1061 if ((mkdir(ctdl_spool_dir, 0700) != 0) && (errno != EEXIST))
1062 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_spool_dir, strerror(errno));
1063 if (chown(ctdl_spool_dir, CTDLUID, (-1)) != 0)
1064 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_spool_dir, strerror(errno));
1065 if ((mkdir(ctdl_netin_dir, 0700) != 0) && (errno != EEXIST))
1066 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_netin_dir, strerror(errno));
1067 if (chown(ctdl_netin_dir, CTDLUID, (-1)) != 0)
1068 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netin_dir, strerror(errno));
1069 if ((mkdir(ctdl_nettmp_dir, 0700) != 0) && (errno != EEXIST))
1070 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_nettmp_dir, strerror(errno));
1071 if (chown(ctdl_nettmp_dir, CTDLUID, (-1)) != 0)
1072 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_nettmp_dir, strerror(errno));
1073 if ((mkdir(ctdl_netout_dir, 0700) != 0) && (errno != EEXIST))
1074 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_netout_dir, strerror(errno));
1075 if (chown(ctdl_netout_dir, CTDLUID, (-1)) != 0)
1076 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netout_dir, strerror(errno));
1080 * Module entry point
1082 CTDL_MODULE_INIT(network_spool)
1086 CtdlREGISTERRoomCfgType(subpending, ParseSubPendingLine, 0, 5, SerializeGeneric, DeleteGenericCfgLine); /// todo: move this to mailinglist manager
1087 CtdlREGISTERRoomCfgType(unsubpending, ParseUnSubPendingLine, 0, 4, SerializeGeneric, DeleteGenericCfgLine); /// todo: move this to mailinglist manager
1088 CtdlREGISTERRoomCfgType(lastsent, ParseLastSent, 1, 1, SerializeLastSent, DeleteLastSent);
1089 CtdlREGISTERRoomCfgType(ignet_push_share, ParseGeneric, 0, 2, SerializeGeneric, DeleteGenericCfgLine); // [remotenode|remoteroomname (optional)]// todo: move this to the ignet client
1090 CtdlREGISTERRoomCfgType(listrecp, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1091 CtdlREGISTERRoomCfgType(digestrecp, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1092 CtdlREGISTERRoomCfgType(participate, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1093 CtdlREGISTERRoomCfgType(roommailalias, ParseRoomAlias, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1095 create_spool_dirs();
1096 //////todo CtdlRegisterCleanupHook(destroy_network_queue_room);
1098 return "network_spool";