+#include "citserver.h"
+#include "threads.h"
+
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
+
+/*
+ * network_talking_to() -- concurrency checker
+ */
+int network_talking_to(char *nodename, int operation) {
+
+ static char *nttlist = NULL;
+ char *ptr = NULL;
+ int i;
+ char buf[SIZ];
+ int retval = 0;
+
+ begin_critical_section(S_NTTLIST);
+
+ switch(operation) {
+
+ case NTT_ADD:
+ if (nttlist == NULL) nttlist = strdup("");
+ if (nttlist == NULL) break;
+ nttlist = (char *)realloc(nttlist,
+ (strlen(nttlist) + strlen(nodename) + 3) );
+ strcat(nttlist, "|");
+ strcat(nttlist, nodename);
+ break;
+
+ case NTT_REMOVE:
+ if (nttlist == NULL) break;
+ if (IsEmptyStr(nttlist)) break;
+ ptr = malloc(strlen(nttlist));
+ if (ptr == NULL) break;
+ strcpy(ptr, "");
+ for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
+ extract_token(buf, nttlist, i, '|', sizeof buf);
+ if ( (!IsEmptyStr(buf))
+ && (strcasecmp(buf, nodename)) ) {
+ strcat(ptr, buf);
+ strcat(ptr, "|");
+ }
+ }
+ free(nttlist);
+ nttlist = ptr;
+ break;
+
+ case NTT_CHECK:
+ if (nttlist == NULL) break;
+ if (IsEmptyStr(nttlist)) break;
+ for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
+ extract_token(buf, nttlist, i, '|', sizeof buf);
+ if (!strcasecmp(buf, nodename)) ++retval;
+ }
+ break;
+ }
+
+ if (nttlist != NULL) lprintf(CTDL_DEBUG, "nttlist=<%s>\n", nttlist);
+ end_critical_section(S_NTTLIST);
+ return(retval);
+}
+
+