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 = strlen(config.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)
185 struct CitContext *CCC = CC;
189 sc = (SpoolControl*)malloc(sizeof(SpoolControl));
190 memset(sc, 0, sizeof(SpoolControl));
191 sc->RNCfg = room_to_spool->OneRNCfg;
192 sc->lastsent = room_to_spool->lastsent;
193 sc->working_ignetcfg = working_ignetcfg;
194 sc->the_netmap = the_netmap;
197 * If the room doesn't exist, don't try to perform its networking tasks.
198 * Normally this should never happen, but once in a while maybe a room gets
199 * queued for networking and then deleted before it can happen.
201 if (CtdlGetRoom(&sc->room, room_to_spool->name) != 0) {
202 syslog(LOG_CRIT, "ERROR: cannot load <%s>\n", room_to_spool->name);
206 if (sc->room.QRhighest <= sc->lastsent)
208 QN_syslog(LOG_DEBUG, "nothing to do for <%s>\n", room_to_spool->name);
213 begin_critical_section(S_NETCONFIGS);
214 if (sc->RNCfg == NULL)
215 sc->RNCfg = CtdlGetNetCfgForRoom(sc->room.QRnumber);
217 if (!HaveSpoolConfig(sc->RNCfg))
219 end_critical_section(S_NETCONFIGS);
221 /* nothing to do for this room... */
225 /* Now lets remember whats needed for the actual work... */
227 for (i=0; i < 4; i++)
229 aggregate_recipients(&sc->Users[SpoolCfgs[i]],
235 if (StrLength(sc->RNCfg->Sender) > 0)
236 sc->Users[roommailalias] = NewStrBufDup(sc->RNCfg->Sender);
237 end_critical_section(S_NETCONFIGS);
244 void CalcListID(SpoolControl *sc)
249 struct CitContext *CCC = CC;
250 char filename[PATH_MAX];
251 #define MAX_LISTIDLENGTH 150
253 assoc_file_name(filename, sizeof filename, &sc->room, ctdl_info_dir);
254 fd = open(filename, 0);
259 if ((fstat(fd, &stbuf) == 0) &&
262 sc->RoomInfo = NewStrBufPlain(NULL, stbuf.st_size + 1);
263 StrBufReadBLOB(sc->RoomInfo, &fd, 0, stbuf.st_size, &err);
268 sc->ListID = NewStrBufPlain(NULL, 1024);
269 if (StrLength(sc->RoomInfo) > 0)
271 const char *Pos = NULL;
272 StrBufSipLine(sc->ListID, sc->RoomInfo, &Pos);
274 if (StrLength(sc->ListID) > MAX_LISTIDLENGTH)
276 StrBufCutAt(sc->ListID, MAX_LISTIDLENGTH, NULL);
277 StrBufAppendBufPlain(sc->ListID, HKEY("..."), 0);
279 StrBufAsciify(sc->ListID, ' ');
283 StrBufAppendBufPlain(sc->ListID, CCC->room.QRname, -1, 0);
286 StrBufAppendBufPlain(sc->ListID, HKEY("<"), 0);
287 RoomName = NewStrBufPlain (sc->room.QRname, -1);
288 StrBufAsciify(RoomName, '_');
289 StrBufReplaceChars(RoomName, ' ', '_');
291 if (StrLength(sc->Users[roommailalias]) > 0)
296 Pos = StrLength(sc->ListID);
297 StrBufAppendBuf(sc->ListID, sc->Users[roommailalias], 0);
298 AtPos = strchr(ChrPtr(sc->ListID) + Pos, '@');
302 StrBufPeek(sc->ListID, AtPos, 0, '.');
307 StrBufAppendBufPlain(sc->ListID, HKEY("room_"), 0);
308 StrBufAppendBuf(sc->ListID, RoomName, 0);
309 StrBufAppendBufPlain(sc->ListID, HKEY("."), 0);
310 StrBufAppendBufPlain(sc->ListID, config.c_fqdn, -1, 0);
313 * roomname <Room-Number.list-id.fqdn>
314 * according to rfc2919.txt it only has to be a uniq identifier
315 * under the domain of the system;
316 * in general MUAs use it to calculate the reply address nowadays.
319 StrBufAppendBufPlain(sc->ListID, HKEY(">"), 0);
321 if (StrLength(sc->Users[roommailalias]) == 0)
323 sc->Users[roommailalias] = NewStrBuf();
325 StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("room_"), 0);
326 StrBufAppendBuf(sc->Users[roommailalias], RoomName, 0);
327 StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("@"), 0);
328 StrBufAppendBufPlain(sc->Users[roommailalias], config.c_fqdn, -1, 0);
330 StrBufLowerCase(sc->Users[roommailalias]);
333 FreeStrBuf(&RoomName);
336 static time_t last_digest_delivery = 0;
339 * Batch up and send all outbound traffic from the current room
341 void network_spoolout_room(SpoolControl *sc)
343 struct CitContext *CCC = CC;
349 * If the room doesn't exist, don't try to perform its networking tasks.
350 * Normally this should never happen, but once in a while maybe a room gets
351 * queued for networking and then deleted before it can happen.
353 memcpy (&CCC->room, &sc->room, sizeof(ctdlroom));
355 syslog(LOG_INFO, "Networking started for <%s>\n", CCC->room.QRname);
359 /* remember where we started... */
360 lastsent = sc->lastsent;
362 /* Fetch the messages we ought to send & prepare them. */
363 CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL,
364 network_spool_msg, sc);
366 if (StrLength(sc->Users[roommailalias]) > 0)
369 len = StrLength(sc->Users[roommailalias]);
370 if (len + 1 > sizeof(buf))
371 len = sizeof(buf) - 1;
372 memcpy(buf, ChrPtr(sc->Users[roommailalias]), len);
377 snprintf(buf, sizeof buf, "room_%s@%s",
378 CCC->room.QRname, config.c_fqdn);
381 for (i=0; buf[i]; ++i) {
382 buf[i] = tolower(buf[i]);
383 if (isspace(buf[i])) buf[i] = '_';
387 /* If we wrote a digest, deliver it and then close it */
388 if (sc->Users[digestrecp] != NULL) {
389 time_t now = time(NULL);
390 time_t secs_today = now % (24 * 60 * 60);
393 if (last_digest_delivery != 0) {
394 delta = now - last_digest_delivery;
395 delta = (24 * 60 * 60) - delta;
398 if ((secs_today < 300) &&
401 if (sc->digestfp == NULL) {
402 sc->digestfp = create_digest_file(&sc->room, 0);
404 if (sc->digestfp != NULL) {
405 last_digest_delivery = now;
406 fprintf(sc->digestfp,
407 " -----------------------------------"
408 "------------------------------------"
410 "You are subscribed to the '%s' "
412 "To post to the list: %s\n",
413 CCC->room.QRname, buf
415 network_deliver_digest(sc); /* deliver */
416 remove_digest_file(&sc->room);
420 if (sc->digestfp != NULL) {
421 fclose(sc->digestfp);
425 /* Now rewrite the config file */
426 if (sc->lastsent != lastsent)
428 begin_critical_section(S_NETCONFIGS);
429 sc->RNCfg = CtdlGetNetCfgForRoom(sc->room.QRnumber);
431 sc->RNCfg->lastsent = sc->lastsent;
432 sc->RNCfg->changed = 1;
433 end_critical_section(S_NETCONFIGS);
438 * Process a buffer containing a single message from a single file
439 * from the inbound queue
441 void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
444 struct CitContext *CCC = CC;
446 struct CtdlMessage *msg = NULL;
449 recptypes *recp = NULL;
450 char target_room[ROOMNAMELEN];
451 struct ser_ret sermsg;
452 char filename[PATH_MAX];
454 const StrBuf *nexthop = NULL;
455 unsigned char firstbyte;
456 unsigned char lastbyte;
458 QN_syslog(LOG_DEBUG, "network_process_buffer() processing %ld bytes\n", size);
460 /* Validate just a little bit. First byte should be FF and * last byte should be 00. */
461 firstbyte = buffer[0];
462 lastbyte = buffer[size-1];
463 if ( (firstbyte != 255) || (lastbyte != 0) ) {
464 QN_syslog(LOG_ERR, "Corrupt message ignored. Length=%ld, firstbyte = %d, lastbyte = %d\n",
465 size, firstbyte, lastbyte);
469 /* Set default target room to trash */
470 strcpy(target_room, TWITROOM);
472 /* Load the message into memory */
473 msg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
474 memset(msg, 0, sizeof(struct CtdlMessage));
475 msg->cm_magic = CTDLMESSAGE_MAGIC;
476 msg->cm_anon_type = buffer[1];
477 msg->cm_format_type = buffer[2];
479 for (pos = 3; pos < size; ++pos) {
481 len = strlen(buffer + pos + 1);
482 CM_SetField(msg, field, buffer + pos + 1, len);
486 /* Check for message routing */
487 if (!CM_IsEmpty(msg, eDestination)) {
488 if (strcasecmp(msg->cm_fields[eDestination], config.c_nodename)) {
490 /* route the message */
491 Buf = NewStrBufPlain(CM_KEY(msg,eDestination));
492 if (CtdlIsValidNode(&nexthop,
498 Netmap_AddMe(msg, HKEY("unknown_user"));
500 /* serialize the message */
501 CtdlSerializeMessage(&sermsg, msg);
504 if (StrLength(nexthop) == 0) {
515 QN_syslog(LOG_DEBUG, "Appending to %s\n", filename);
516 fp = fopen(filename, "ab");
518 fwrite(sermsg.ser, sermsg.len, 1, fp);
522 QN_syslog(LOG_ERR, "%s: %s\n", filename, strerror(errno));
530 else { /* invalid destination node name */
534 "A message you sent could not be delivered due to an invalid destination node"
535 " name. Please check the address and try sending the message again.\n");
544 * Check to see if we already have a copy of this message, and
545 * abort its processing if so. (We used to post a warning to Aide>
546 * every time this happened, but the network is now so densely
547 * connected that it's inevitable.)
549 if (network_usetable(msg) != 0) {
554 /* Learn network topology from the path */
555 if (!CM_IsEmpty(msg, eNodeName) && !CM_IsEmpty(msg, eMessagePath)) {
556 NetworkLearnTopology(msg->cm_fields[eNodeName],
557 msg->cm_fields[eMessagePath],
562 /* Is the sending node giving us a very persuasive suggestion about
563 * which room this message should be saved in? If so, go with that.
565 if (!CM_IsEmpty(msg, eRemoteRoom)) {
566 safestrncpy(target_room, msg->cm_fields[eRemoteRoom], sizeof target_room);
569 /* Otherwise, does it have a recipient? If so, validate it... */
570 else if (!CM_IsEmpty(msg, eRecipient)) {
571 recp = validate_recipients(msg->cm_fields[eRecipient], NULL, 0);
572 if (recp != NULL) if (recp->num_error != 0) {
574 "A message you sent could not be delivered due to an invalid address.\n"
575 "Please check the address and try sending the message again.\n");
577 free_recipients(recp);
578 QNM_syslog(LOG_DEBUG, "Bouncing message due to invalid recipient address.\n");
581 strcpy(target_room, ""); /* no target room if mail */
584 /* Our last shot at finding a home for this message is to see if
585 * it has the eOriginalRoom (O) field (Originating room) set.
587 else if (!CM_IsEmpty(msg, eOriginalRoom)) {
588 safestrncpy(target_room, msg->cm_fields[eOriginalRoom], sizeof target_room);
591 /* Strip out fields that are only relevant during transit */
592 CM_FlushField(msg, eDestination);
593 CM_FlushField(msg, eRemoteRoom);
595 /* save the message into a room */
596 if (PerformNetprocHooks(msg, target_room) == 0) {
597 msg->cm_flags = CM_SKIP_HOOKS;
598 CtdlSubmitMsg(msg, recp, target_room, 0);
601 free_recipients(recp);
606 * Process a single message from a single file from the inbound queue
608 void network_process_message(FILE *fp,
611 HashList *working_ignetcfg,
612 HashList *the_netmap,
619 hold_pos = ftell(fp);
620 size = msgend - msgstart + 1;
621 buffer = malloc(size);
622 if (buffer != NULL) {
623 fseek(fp, msgstart, SEEK_SET);
624 if (fread(buffer, size, 1, fp) > 0) {
625 network_process_buffer(buffer,
634 fseek(fp, hold_pos, SEEK_SET);
639 * Process a single file from the inbound queue
641 void network_process_file(char *filename,
642 HashList *working_ignetcfg,
643 HashList *the_netmap,
646 struct CitContext *CCC = CC;
648 long msgstart = (-1L);
654 fp = fopen(filename, "rb");
656 QN_syslog(LOG_CRIT, "Error opening %s: %s\n", filename, strerror(errno));
660 fseek(fp, 0L, SEEK_END);
661 QN_syslog(LOG_INFO, "network: processing %ld bytes from %s\n", ftell(fp), filename);
664 /* Look for messages in the data stream and break them out */
665 while (ch = getc(fp), ch >= 0) {
668 if (msgstart >= 0L) {
670 network_process_message(fp,
685 if (msgstart >= 0L) {
686 network_process_message(fp,
697 "network: processed %d messages in %s\n",
707 * Process anything in the inbound queue
709 void network_do_spoolin(HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
711 struct CitContext *CCC = CC;
714 struct dirent *filedir_entry;
716 char filename[PATH_MAX];
717 static time_t last_spoolin_mtime = 0L;
722 * Check the spoolin directory's modification time. If it hasn't
723 * been touched, we don't need to scan it.
725 if (stat(ctdl_netin_dir, &statbuf)) return;
726 if (statbuf.st_mtime == last_spoolin_mtime) {
727 QNM_syslog(LOG_DEBUG, "network: nothing in inbound queue\n");
730 last_spoolin_mtime = statbuf.st_mtime;
731 QNM_syslog(LOG_DEBUG, "network: processing inbound queue\n");
734 * Ok, there's something interesting in there, so scan it.
736 dp = opendir(ctdl_netin_dir);
737 if (dp == NULL) return;
739 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
745 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
746 (filedir_entry != NULL))
748 #ifdef _DIRENT_HAVE_D_NAMLEN
749 d_namelen = filedir_entry->d_namlen;
752 d_namelen = strlen(filedir_entry->d_name);
755 #ifdef _DIRENT_HAVE_D_TYPE
756 d_type = filedir_entry->d_type;
760 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
761 continue; /* Ignore backup files... */
763 if ((d_namelen == 1) &&
764 (filedir_entry->d_name[0] == '.'))
767 if ((d_namelen == 2) &&
768 (filedir_entry->d_name[0] == '.') &&
769 (filedir_entry->d_name[1] == '.'))
772 if (d_type == DT_UNKNOWN) {
780 filedir_entry->d_name);
782 if (lstat(path, &s) == 0) {
783 d_type = IFTODT(s.st_mode);
791 case DT_LNK: /* TODO: check whether its a file or a directory */
799 network_process_file(filename,
811 * Step 1: consolidate files in the outbound queue into one file per neighbor node
812 * Step 2: delete any files in the outbound queue that were for neighbors who no longer exist.
814 void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netmap)
816 struct CitContext *CCC = CC;
822 struct dirent *filedir_entry;
824 char spooloutfilename[PATH_MAX];
825 char filename[PATH_MAX];
826 const StrBuf *nexthop;
834 /* Step 1: consolidate files in the outbound queue into one file per neighbor node */
835 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
836 if (d == NULL) return;
838 dp = opendir(ctdl_netout_dir);
844 NextHop = NewStrBuf();
845 memset(&IOB, 0, sizeof(IOBuffer));
846 memset(&FDIO, 0, sizeof(FDIOBuffer));
849 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
850 (filedir_entry != NULL))
852 #ifdef _DIRENT_HAVE_D_NAMLEN
853 d_namelen = filedir_entry->d_namlen;
856 d_namelen = strlen(filedir_entry->d_name);
859 #ifdef _DIRENT_HAVE_D_TYPE
860 d_type = filedir_entry->d_type;
864 if (d_type == DT_DIR)
867 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
868 continue; /* Ignore backup files... */
870 if ((d_namelen == 1) &&
871 (filedir_entry->d_name[0] == '.'))
874 if ((d_namelen == 2) &&
875 (filedir_entry->d_name[0] == '.') &&
876 (filedir_entry->d_name[1] == '.'))
879 pch = strchr(filedir_entry->d_name, '@');
887 filedir_entry->d_name);
890 filedir_entry->d_name,
891 pch - filedir_entry->d_name);
893 snprintf(spooloutfilename,
894 sizeof spooloutfilename,
899 QN_syslog(LOG_DEBUG, "Consolidate %s to %s\n", filename, ChrPtr(NextHop));
900 if (CtdlNetworkTalkingTo(SKEY(NextHop), NTT_CHECK)) {
903 "Currently online with %s - skipping for now\n",
911 const char *err = NULL;
912 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_ADD);
914 infd = open(filename, O_RDONLY);
918 "failed to open %s for reading due to %s; skipping.\n",
919 filename, strerror(errno)
921 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
925 outfd = open(spooloutfilename,
926 O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY,
930 outfd = open(spooloutfilename,
931 O_EXCL|O_NONBLOCK|O_WRONLY,
937 "failed to open %s for reading due to %s; skipping.\n",
938 spooloutfilename, strerror(errno)
941 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
945 dsize = lseek(outfd, 0, SEEK_END);
946 lseek(outfd, -dsize, SEEK_SET);
948 fstat(infd, &statbuf);
949 fsize = statbuf.st_size;
951 fsize = lseek(infd, 0, SEEK_END);
954 FDIOBufferInit(&FDIO, &IOB, outfd, fsize + dsize);
955 FDIO.ChunkSendRemain = fsize;
956 FDIO.TotalSentAlready = dsize;
959 do {} while ((FileMoveChunked(&FDIO, &err) > 0) && (err == NULL));
963 "Spoolfile %s now "SIZE_T_FMT" k\n",
971 "failed to append to %s [%s]; rolling back..\n",
972 spooloutfilename, strerror(errno)
974 /* whoops partial append?? truncate spooloutfilename again! */
975 ftruncate(outfd, dsize);
977 FDIOBufferDelete(&FDIO);
980 CtdlNetworkTalkingTo(SKEY(NextHop), NTT_REMOVE);
986 FreeStrBuf(&NextHop);
988 "skipping Spoolcleanup because of %d files unprocessed.\n",
995 /* Step 2: delete any files in the outbound queue that were for neighbors who no longer exist */
996 dp = opendir(ctdl_netout_dir);
998 FreeStrBuf(&NextHop);
1003 while ((readdir_r(dp, d, &filedir_entry) == 0) &&
1004 (filedir_entry != NULL))
1006 #ifdef _DIRENT_HAVE_D_NAMLEN
1007 d_namelen = filedir_entry->d_namlen;
1010 d_namelen = strlen(filedir_entry->d_name);
1013 #ifdef _DIRENT_HAVE_D_TYPE
1014 d_type = filedir_entry->d_type;
1016 d_type = DT_UNKNOWN;
1018 if (d_type == DT_DIR)
1021 if ((d_namelen == 1) &&
1022 (filedir_entry->d_name[0] == '.'))
1025 if ((d_namelen == 2) &&
1026 (filedir_entry->d_name[0] == '.') &&
1027 (filedir_entry->d_name[1] == '.'))
1030 pch = strchr(filedir_entry->d_name, '@');
1031 if (pch == NULL) /* no @ in name? consolidated file. */
1034 StrBufPlain(NextHop,
1035 filedir_entry->d_name,
1036 pch - filedir_entry->d_name);
1042 filedir_entry->d_name
1045 i = CtdlIsValidNode(&nexthop,
1051 if ( (i != 0) || (StrLength(nexthop) > 0) ) {
1055 FreeStrBuf(&NextHop);
1060 void free_spoolcontrol_struct(SpoolControl **sc)
1062 free_spoolcontrol_struct_members(*sc);
1067 void free_spoolcontrol_struct_members(SpoolControl *sc)
1070 FreeStrBuf(&sc->RoomInfo);
1071 FreeStrBuf(&sc->ListID);
1072 for (i = 0; i < maxRoomNetCfg; i++)
1073 FreeStrBuf(&sc->Users[i]);
1079 * It's ok if these directories already exist. Just fail silently.
1081 void create_spool_dirs(void) {
1082 if ((mkdir(ctdl_spool_dir, 0700) != 0) && (errno != EEXIST))
1083 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_spool_dir, strerror(errno));
1084 if (chown(ctdl_spool_dir, CTDLUID, (-1)) != 0)
1085 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_spool_dir, strerror(errno));
1086 if ((mkdir(ctdl_netin_dir, 0700) != 0) && (errno != EEXIST))
1087 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_netin_dir, strerror(errno));
1088 if (chown(ctdl_netin_dir, CTDLUID, (-1)) != 0)
1089 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netin_dir, strerror(errno));
1090 if ((mkdir(ctdl_nettmp_dir, 0700) != 0) && (errno != EEXIST))
1091 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_nettmp_dir, strerror(errno));
1092 if (chown(ctdl_nettmp_dir, CTDLUID, (-1)) != 0)
1093 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_nettmp_dir, strerror(errno));
1094 if ((mkdir(ctdl_netout_dir, 0700) != 0) && (errno != EEXIST))
1095 syslog(LOG_EMERG, "unable to create directory [%s]: %s", ctdl_netout_dir, strerror(errno));
1096 if (chown(ctdl_netout_dir, CTDLUID, (-1)) != 0)
1097 syslog(LOG_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netout_dir, strerror(errno));
1101 * Module entry point
1103 CTDL_MODULE_INIT(network_spool)
1107 CtdlREGISTERRoomCfgType(subpending, ParseSubPendingLine, 0, 5, SerializeGeneric, DeleteGenericCfgLine); /// todo: move this to mailinglist manager
1108 CtdlREGISTERRoomCfgType(unsubpending, ParseUnSubPendingLine, 0, 4, SerializeGeneric, DeleteGenericCfgLine); /// todo: move this to mailinglist manager
1109 CtdlREGISTERRoomCfgType(lastsent, ParseLastSent, 1, 1, SerializeLastSent, DeleteLastSent);
1110 CtdlREGISTERRoomCfgType(ignet_push_share, ParseGeneric, 0, 2, SerializeGeneric, DeleteGenericCfgLine); // [remotenode|remoteroomname (optional)]// todo: move this to the ignet client
1111 CtdlREGISTERRoomCfgType(listrecp, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1112 CtdlREGISTERRoomCfgType(digestrecp, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1113 CtdlREGISTERRoomCfgType(participate, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1114 CtdlREGISTERRoomCfgType(roommailalias, ParseRoomAlias, 0, 1, SerializeGeneric, DeleteGenericCfgLine);
1116 create_spool_dirs();
1117 //////todo CtdlRegisterCleanupHook(destroy_network_queue_room);
1119 return "network_spool";