char *inbuf;
size_t inbufdata, inbufsize;
off_t curread, totalsize;
- int freeing;
+ int close;
struct timer *timeout;
struct qcmdqueue queue;
struct transfer *transfer;
if((buf = path2nmdc(peer->transfer->path, DCCHARSET)) == NULL)
{
transferseterror(peer->transfer, TRNSE_NOTFOUND);
- freedcpeer(peer);
+ peer->close = 1;
return;
}
/* The transfer will be restarted later from
if((buf = getadcid(peer)) == NULL)
{
transferseterror(peer->transfer, TRNSE_NOTFOUND);
- freedcpeer(peer);
+ peer->close = 1;
return;
}
sendadc(peer->sk, buf);
if(forkfilter(peer->transfer))
{
flog(LOG_WARNING, "could not fork filter for transfer %i: %s", peer->transfer->id, strerror(errno));
- freedcpeer(peer);
+ peer->close = 1;
return;
}
CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer);
if((buf = getadcid(peer)) == NULL)
{
transferseterror(peer->transfer, TRNSE_NOTFOUND);
- freedcpeer(peer);
+ peer->close = 1;
return;
}
sendadc(peer->sk, buf);
if((buf = path2nmdc(peer->transfer->path, "UTF-8")) == NULL)
{
transferseterror(peer->transfer, TRNSE_NOTFOUND);
- freedcpeer(peer);
+ peer->close = 1;
return;
}
qstrf(peer->sk, "$UGetBlock %ji %ji %s|", (intmax_t)peer->transfer->curpos, (intmax_t)(peer->transfer->size - peer->transfer->curpos), buf);
if((buf = path2nmdc(peer->transfer->path, DCCHARSET)) == NULL)
{
transferseterror(peer->transfer, TRNSE_NOTFOUND);
- freedcpeer(peer);
+ peer->close = 1;
return;
}
qstrf(peer->sk, "$Get %s$%ji|", buf, (intmax_t)peer->transfer->curpos + 1);
free(peer->wcsname);
if((peer->wcsname = icmbstowcs(peer->nativename, peer->charset)) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(peer->accepted)
{
if((peer->transfer == NULL) || (mydir != peer->direction))
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(peer->direction == TRNSD_DOWN)
} else {
if(peer->wcsname == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
peer->direction = mydir;
{
if(confgetint("transfer", "ulquota") && hasupload(&dcnet, peer->wcsname))
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
transfer = newupload(peer->fn, &dcnet, peer->wcsname, &dctransfer, peer);
} else {
if((transfer = finddownload(peer->wcsname)) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
transferattach(transfer, &dctransfer, peer);
{
if(peer->wcsname == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
sendmynick(peer);
{
if(confgetint("transfer", "ulquota") && hasupload(&dcnet, peer->wcsname))
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
peer->direction = TRNSD_UP;
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
size = strtoll(args, NULL, 10);
{
transfersetsize(peer->transfer, size);
transfer = peer->transfer;
- freedcpeer(peer);
+ peer->close = 1;
+ resettransfer(transfer);
trytransferbypeer(transfer->fnet, transfer->peerid);
return;
}
resettransfer(peer->transfer);
return;
}
- freedcpeer(peer);
+ peer->close = 1;
}
static void cmd_maxedout(struct socket *sk, struct dcpeer *peer, char *cmd, char *args)
resettransfer(peer->transfer);
return;
}
- freedcpeer(peer);
+ peer->close = 1;
}
static struct
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if((p = strchr(args, '$')) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
*(p++) = 0;
if((offset = (strtoll(p, NULL, 10) - 1)) < 0)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(((fd = openfilelist(args)) < 0) && (errno != 0))
{
qstr(sk, "$Error Could not send file list|");
- freedcpeer(peer);
+ peer->close = 1;
return;
} else if(fd >= 0) {
if((buf2 = nmdc2path(args, DCCHARSET)) != NULL) {
if((node = resdcpath(args, DCCHARSET, '\\')) == NULL)
{
qstrf(sk, "$Error File not in share|");
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if((fd = opensharecache(node)) < 0)
{
qstrf(sk, "$Error %s|", strerror(errno));
- freedcpeer(peer);
+ peer->close = 1;
return;
}
buf = getfspath(node);
close(fd);
flog(LOG_WARNING, "could not stat file %ls: %s", node->name, strerror(errno));
qstrf(sk, "$Error|");
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(sb.st_size < 65536)
if(!peer->transfer->flags.b.minislot && (slotsleft() < 1)) {
close(fd);
qstr(sk, "$MaxedOut|");
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if((offset != 0) && (lseek(fd, offset, SEEK_SET) < 0))
{
close(fd);
qstrf(sk, "$Error Offset out of range|");
- freedcpeer(peer);
+ peer->close = 1;
return;
}
lesk = wrapsock(fd);
{
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(peer->transfer->localend == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
peer->ptclose = 1;
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
p = args;
if((p2 = strchr(p, ' ')) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
*(p2++) = 0;
p = p2;
if((p2 = strchr(p, ' ')) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
*(p2++) = 0;
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if((argv = parseadc(args)) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(parrlen(argv) < 4)
{
- freedcpeer(peer);
+ peer->close = 1;
goto out;
}
start = strtoll(argv[2], NULL, 10);
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if((argv = parseadc(args)) == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
if(parrlen(argv) < 4)
{
- freedcpeer(peer);
+ peer->close = 1;
goto out;
}
start = strtoll(argv[2], NULL, 10);
if((start != 0) || (numbytes % 24 != 0))
{
/* Weird. Bail out. */
- freedcpeer(peer);
+ peer->close = 1;
goto out;
}
if(peer->timeout != NULL)
} else if(!strcmp(argv[0], "file")) {
if(start != peer->transfer->curpos)
{
- freedcpeer(peer);
+ peer->close = 1;
goto out;
}
if(start + numbytes != peer->transfer->size)
{
transfersetsize(peer->transfer, start + numbytes);
- freedcpeer(peer);
+ peer->close = 1;
goto out;
}
startdl(peer);
}
} else {
/* We certainly didn't request this...*/
- freedcpeer(peer);
+ peer->close = 1;
goto out;
}
if(peer->transfer == NULL)
{
- freedcpeer(peer);
+ peer->close = 1;
return;
}
numbytes = strtoll(args, NULL, 10);
if(peer->transfer->size - peer->transfer->curpos != numbytes)
{
transfersetsize(peer->transfer, peer->transfer->curpos + numbytes);
- freedcpeer(peer);
+ peer->close = 1;
return;
}
startdl(peer);
static void dctransdetach(struct transfer *transfer, struct dcpeer *peer)
{
CBUNREG(transfer, trans_filterout, peer);
- if(peer->freeing)
- return;
peer->transfer = NULL;
- freedcpeer(peer);
+ peer->close = 1;
}
static void dctransgotdata(struct transfer *transfer, struct dcpeer *peer)
int i;
struct qcommand *qcmd;
- peer->freeing = 1;
if(peers == peer)
peers = peer->next;
if(peer->next != NULL)
break;
}
quota = 20;
- for(peer = peers; peer != NULL; peer = nextpeer)
+ for(peer = peers; peer != NULL; peer = peer->next)
{
- nextpeer = peer->next;
- while((quota > 0) && ((qcmd = ulqcmd(&peer->queue)) != NULL))
+ while(!peer->close && (quota > 0) && ((qcmd = ulqcmd(&peer->queue)) != NULL))
{
if(peer->timeout != NULL)
canceltimer(peer->timeout);
if(quota < 1)
break;
}
+ for(peer = peers; peer != NULL; peer = nextpeer)
+ {
+ nextpeer = peer->next;
+ if(peer->close)
+ freedcpeer(peer);
+ }
return(ret);
}