style cleanup
[citadel.git] / citadel / nttlist.c
1 /*
2  * This module handles shared rooms, inter-Citadel mail, and outbound
3  * mailing list processing.
4  *
5  * Copyright (c) 2000-2017 by the citadel.org team
6  *
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.
9  *
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.
14  *
15  */
16 #include "sysdep.h"
17 #include <stdio.h>
18 #include <libcitadel.h>
19 #include "ctdl_module.h"
20 #include "serv_extensions.h"
21
22 /*-----------------------------------------------------------------------------*
23  *                 Network maps: evaluate other nodes                          *
24  *-----------------------------------------------------------------------------*/
25
26 /*
27  * network_talking_to()  --  concurrency checker
28  */
29 static HashList *nttlist = NULL;
30 int CtdlNetworkTalkingTo(const char *nodename, long len, int operation)
31 {
32
33         int retval = 0;
34         HashPos *Pos = NULL;
35         void *vdata;
36
37         begin_critical_section(S_NTTLIST);
38
39         switch(operation) {
40
41                 case NTT_ADD:
42                         if (nttlist == NULL) 
43                                 nttlist = NewHash(1, NULL);
44                         Put(nttlist, nodename, len, NewStrBufPlain(nodename, len), HFreeStrBuf);
45                         syslog(LOG_DEBUG, "nttlist: added <%s>\n", nodename);
46                         break;
47                 case NTT_REMOVE:
48                         if ((nttlist == NULL) ||
49                             (GetCount(nttlist) == 0))
50                                 break;
51                         Pos = GetNewHashPos(nttlist, 1);
52                         if (GetHashPosFromKey (nttlist, nodename, len, Pos))
53                                 DeleteEntryFromHash(nttlist, Pos);
54                         DeleteHashPos(&Pos);
55                         syslog(LOG_DEBUG, "nttlist: removed <%s>\n", nodename);
56
57                         break;
58
59                 case NTT_CHECK:
60                         if ((nttlist == NULL) ||
61                             (GetCount(nttlist) == 0))
62                                 break;
63                         if (GetHash(nttlist, nodename, len, &vdata))
64                                 retval ++;
65                         syslog(LOG_DEBUG, "nttlist: have [%d] <%s>\n", retval, nodename);
66                         break;
67         }
68
69         end_critical_section(S_NTTLIST);
70         return(retval);
71 }
72
73 void cleanup_nttlist(void)
74 {
75         begin_critical_section(S_NTTLIST);
76         DeleteHash(&nttlist);
77         end_critical_section(S_NTTLIST);
78 }
79
80
81
82
83 /*
84  * Module entry point
85  */
86 CTDL_MODULE_INIT(nttlist)
87 {
88         if (!threading)
89         {
90                 CtdlRegisterCleanupHook(cleanup_nttlist);
91         }
92         return "nttlist";
93 }