/*
* network_talking_to() -- concurrency checker
*/
-static char *nttlist = NULL;
-int network_talking_to(const char *nodename, int operation) {
+static HashList *nttlist = NULL;
+int network_talking_to(const char *nodename, long len, int operation) {
- char *ptr = NULL;
- int i;
- char buf[SIZ];
int retval = 0;
+ HashPos *Pos = NULL;
+ void *vdata;
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);
+ if (nttlist == NULL)
+ nttlist = NewHash(1, NULL);
+ Put(nttlist, nodename, len, NewStrBufPlain(nodename, len), HFreeStrBuf);
+ syslog(LOG_DEBUG, "nttlist: added <%s>\n", 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;
+ if ((nttlist == NULL) ||
+ (GetCount(nttlist) == 0))
+ break;
+ Pos = GetNewHashPos(nttlist, 1);
+ GetHashPosFromKey (nttlist, nodename, len, Pos);
+
+ DeleteEntryFromHash(nttlist, Pos);
+ DeleteHashPos(&Pos);
+ syslog(LOG_DEBUG, "nttlist: removed <%s>\n", nodename);
+
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;
- }
+ if ((nttlist == NULL) ||
+ (GetCount(nttlist) == 0))
+ break;
+ if (!GetHash(nttlist, nodename, len, &vdata))
+ retval ++;
+ syslog(LOG_DEBUG, "nttlist: have [%d] <%s>\n", retval, nodename);
break;
}
- if (nttlist != NULL) syslog(LOG_DEBUG, "nttlist=<%s>\n", nttlist);
end_critical_section(S_NTTLIST);
return(retval);
}
void cleanup_nttlist(void)
{
begin_critical_section(S_NTTLIST);
- if (nttlist != NULL)
- free(nttlist);
- nttlist = NULL;
+ DeleteHash(&nttlist);
end_critical_section(S_NTTLIST);
}
void OpenCmdResult (char *, const char *);
void abort_upl (CitContext *who);
-int network_talking_to(const char *nodename, int operation);
+int network_talking_to(const char *nodename, long len, int operation);
/*
* Operations that can be performed by network_talking_to()
{
char *working_ignetcfg;
char node[256];
+ long nodelen;
char pass[256];
int v;
char err_buf[SIZ];
/* Authenticate */
- extract_token(node, cmdbuf, 0, '|', sizeof node);
+ nodelen = extract_token(node, cmdbuf, 0, '|', sizeof node);
extract_token(pass, cmdbuf, 1, '|', sizeof pass);
/* load the IGnet Configuration to check node validity */
return;
}
- if (network_talking_to(node, NTT_CHECK)) {
+ if (network_talking_to(node, nodelen, NTT_CHECK)) {
syslog(LOG_WARNING, "Duplicate session for network node <%s>", node);
cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
free(working_ignetcfg);
}
safestrncpy(CC->net_node, node, sizeof CC->net_node);
- network_talking_to(node, NTT_ADD);
+ network_talking_to(node, nodelen, NTT_ADD);
syslog(LOG_NOTICE, "Network node <%s> logged in from %s [%s]\n",
CC->net_node, CC->cs_host, CC->cs_addr
);
char filename[PATH_MAX];
char cmd[PATH_MAX];
char nexthop[256];
+ long nexthoplen;
int i;
char *ptr;
&& (strcmp(d->d_name, ".."))
&& (strchr(d->d_name, '@') != NULL)
) {
- safestrncpy(nexthop, d->d_name, sizeof nexthop);
+ nexthoplen = safestrncpy(nexthop, d->d_name, sizeof nexthop);
ptr = strchr(nexthop, '@');
- if (ptr) *ptr = 0;
+ if (ptr) {
+ *ptr = 0;
+ nexthoplen = ptr - nexthop;
+ }
snprintf(filename,
sizeof filename,
);
syslog(LOG_DEBUG, "Consolidate %s to %s\n", filename, nexthop);
- if (network_talking_to(nexthop, NTT_CHECK)) {
+ if (network_talking_to(nexthop, nexthoplen, NTT_CHECK)) {
syslog(LOG_DEBUG,
"Currently online with %s - skipping for now\n",
nexthop
);
}
else {
- network_talking_to(nexthop, NTT_ADD);
+ network_talking_to(nexthop, nexthoplen, NTT_ADD);
snprintf(cmd, sizeof cmd, "/bin/cat %s >>%s/%s && /bin/rm -f %s",
filename,
ctdl_netout_dir, nexthop,
filename
);
system(cmd);
- network_talking_to(nexthop, NTT_REMOVE);
+ network_talking_to(nexthop, nexthoplen, NTT_REMOVE);
}
}
}
* If we were talking to a network node, we're not anymore...
*/
if (!IsEmptyStr(CCC->net_node)) {
- network_talking_to(CCC->net_node, NTT_REMOVE);
+ network_talking_to(CCC->net_node, strlen(CCC->net_node), NTT_REMOVE);
}
/* Run any hooks registered by modules... */