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)
{
}
}
+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;
- CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer);
+ 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;
- CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer);
+ peerattach(peer, transfer);
qstrf(sk, "$Direction %s %i|", (peer->direction == TRNSD_UP)?"Upload":"Download", rand() % 10000);
qstrf(sk, "$Key %s|", key);
free(key);
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)
static void dataerr(struct socket *sk, int errno, struct transfer *transfer)
{
- if(transfer->curpos >= transfer->size) {
- transfersetstate(transfer, TRNS_DONE);
- if(transfer->localend != NULL) {
- closesock(transfer->localend);
- quitsock(transfer->localend);
- transfer->localend = NULL;
- }
- } else {
- if(transfer->dir == TRNSD_DOWN)
+ if(transfer->dir == TRNSD_DOWN) {
+ if(transfer->curpos >= transfer->size) {
+ transfersetstate(transfer, TRNS_DONE);
+ if(transfer->localend != NULL) {
+ closesock(transfer->localend);
+ quitsock(transfer->localend);
+ transfer->localend = NULL;
+ }
+ } else {
resettransfer(transfer);
- else if(transfer->dir == TRNSD_UP)
+ }
+ } else if(transfer->dir == TRNSD_UP) {
transfer->close = 1;
}
}