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.
18 #include <libcitadel.h>
19 #include "ctdl_module.h"
20 #include "serv_extensions.h"
22 /*-----------------------------------------------------------------------------*
23 * Network maps: evaluate other nodes *
24 *-----------------------------------------------------------------------------*/
25 int NTTDebugEnabled = 0;
26 int NTTDumpEnabled = 0;
29 * network_talking_to() -- concurrency checker
31 static HashList *nttlist = NULL;
32 int CtdlNetworkTalkingTo(const char *nodename, long len, int operation)
39 begin_critical_section(S_NTTLIST);
45 nttlist = NewHash(1, NULL);
46 Put(nttlist, nodename, len, NewStrBufPlain(nodename, len), HFreeStrBuf);
47 if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: added <%s>\n", nodename);
50 if ((nttlist == NULL) ||
51 (GetCount(nttlist) == 0))
53 Pos = GetNewHashPos(nttlist, 1);
54 if (GetHashPosFromKey (nttlist, nodename, len, Pos))
55 DeleteEntryFromHash(nttlist, Pos);
57 if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: removed <%s>\n", nodename);
62 if ((nttlist == NULL) ||
63 (GetCount(nttlist) == 0))
65 if (GetHash(nttlist, nodename, len, &vdata))
67 if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: have [%d] <%s>\n", retval, nodename);
78 NTTDump = NewStrBuf ();
80 It = GetNewHashPos(nttlist, 0);
81 while (GetNextHashPos(nttlist, It, &len, &Key, &v))
83 if (StrLength(NTTDump) > 0)
84 StrBufAppendBufPlain(NTTDump, HKEY("|"), 0);
85 StrBufAppendBuf(NTTDump, (StrBuf*) v, 0);
89 syslog(LOG_DEBUG, "nttlist: Dump: [%d] <%s>\n",
94 end_critical_section(S_NTTLIST);
98 void cleanup_nttlist(void)
100 begin_critical_section(S_NTTLIST);
101 DeleteHash(&nttlist);
102 end_critical_section(S_NTTLIST);
110 void SetNTTDebugEnabled(const int n)
115 void SetNTTDumpEnabled(const int n)
125 CTDL_MODULE_INIT(nttlist)
129 CtdlRegisterDebugFlagHook(HKEY("networktalkingto"), SetNTTDebugEnabled, &NTTDebugEnabled);
130 CtdlRegisterDebugFlagHook(HKEY("dumpnetworktalkingto"), SetNTTDumpEnabled, &NTTDumpEnabled);
132 CtdlRegisterCleanupHook(cleanup_nttlist);