static void updatexmlbz2list(void);
static void requestfile(struct dcpeer *peer);
static void updatelists(int now);
+static int trdestroycb(struct transfer *transfer, struct dcpeer *peer);
static int reservedchar(unsigned char c)
{
peer->close = 1;
return;
}
- CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer);
return;
}
if(supports(peer, "adcget"))
struct dchub *hub;
hub = fn->data;
- if(hub->nativename == NULL)
+ if(hub->nativename != NULL)
free(hub->nativename);
hub->nativename = sstrdup(args);
buf = icmbstowcs(args, hub->charset);
}
}
+static void peerattach(struct dcpeer *peer, struct transfer *transfer)
+{
+ peer->transfer = transfer;
+ CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer);
+ CBREG(peer->transfer, trans_destroy, (int (*)(struct transfer *, void *))trdestroycb, NULL, peer);
+}
+
static void cmd_direction(struct socket *sk, struct dcpeer *peer, char *cmd, char *args)
{
char *p;
transfersetstate(transfer, TRNS_HS);
}
transfersetnick(transfer, peer->wcsname);
- peer->transfer = transfer;
+ peerattach(peer, transfer);
if(peer->extended)
sendsupports(peer);
qstrf(sk, "$Direction %s %i|", (peer->direction == TRNSD_UP)?"Upload":"Download", rand() % 10000);
transfersetstate(transfer, TRNS_HS);
}
transfersetnick(transfer, peer->wcsname);
- peer->transfer = transfer;
+ peerattach(peer, transfer);
qstrf(sk, "$Direction %s %i|", (peer->direction == TRNSD_UP)?"Upload":"Download", rand() % 10000);
qstrf(sk, "$Key %s|", key);
free(key);
} else if(fd >= 0) {
if((wbuf = adc2path(argv[1])) != NULL)
transfersetpath(peer->transfer, wbuf);
+ free(wbuf);
peer->transfer->flags.b.minislot = 1;
}
if(fd < 0)
}
if(peer->ptclose)
{
- freedcpeer(peer);
+ peer->close = 1;
} else {
if(peer->timeout == NULL)
peer->timeout = timercallback(ntime() + 180, (void (*)(int, void *))peertimeout, peer);
}
}
+static void peerdetach(struct dcpeer *peer)
+{
+ CBUNREG(peer->transfer, trans_filterout, peer);
+ CBUNREG(peer->transfer, trans_destroy, peer);
+ closesock(peer->trpipe);
+ quitsock(peer->trpipe);
+ peer->trpipe = NULL;
+ peer->transfer = NULL;
+}
+
+static int trdestroycb(struct transfer *transfer, struct dcpeer *peer)
+{
+ peerdetach(peer);
+ peer->close = 1;
+ return(0);
+}
+
static void transread(struct socket *sk, struct dcpeer *peer)
{
void *buf;
size_t bufsize;
+ if(peer->transfer == NULL) {
+ freedcpeer(peer);
+ return;
+ }
if(sockqueueleft(peer->trpipe) < 0)
return;
if((buf = sockgetinbuf(sk, &bufsize)) != NULL)
}
if(peer->transfer->curpos >= peer->transfer->size)
{
- closesock(peer->trpipe);
- quitsock(peer->trpipe);
- peer->trpipe = NULL;
- peer->transfer = NULL;
+ peerdetach(peer);
peer->close = 1;
return;
}
freedcpeer(peer);
return;
}
- closesock(peer->trpipe);
- quitsock(peer->trpipe);
- peer->trpipe = NULL;
- peer->transfer = NULL;
+ peerdetach(peer);
peer->close = 1;
}
{
peer->state = PEER_SYNC;
dctransgotdata(peer->transfer, peer);
- CBUNREG(peer->transfer, trans_filterout, peer);
+ peerdetach(peer);
+ if(peer->state != PEER_CMD)
+ peer->close = 1;
}
static struct socket *mktrpipe(struct dcpeer *peer)
new = smalloc(sizeof(*new));
memset(new, 0, sizeof(*new));
- new->transfer = NULL;
getsock(sk);
new->sk = sk;
if(confgetint("dc", "dcppemu"))
peer->next->prev = peer->prev;
if(peer->prev != NULL)
peer->prev->next = peer->next;
- if(peer->trpipe != NULL) {
- closesock(peer->trpipe);
- quitsock(peer->trpipe);
- }
if(peer->transfer != NULL)
- {
- CBUNREG(peer->transfer, trans_filterout, peer);
- if(peer->transfer->dir == TRNSD_UP)
- peer->transfer->close = 1;
- if(peer->transfer->dir == TRNSD_DOWN)
- resettransfer(peer->transfer);
- }
+ peerdetach(peer);
if(peer->timeout != NULL)
canceltimer(peer->timeout);
if(peer->sk->data == peer)