X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ffnet-dc.c;h=7cbb32ea45a8d370b0900d574ccae2f15cd376f3;hb=ddb3658e4a9d9efb7a8628fee483e5371c426d12;hp=54daeb7aeb2a9ace9ae7cd892f67ec2b4eed4fd5;hpb=2a157d1a2ca04bc1a5c8b2e9de69697bda89ce1c;p=doldaconnect.git diff --git a/daemon/fnet-dc.c b/daemon/fnet-dc.c index 54daeb7..7cbb32e 100644 --- a/daemon/fnet-dc.c +++ b/daemon/fnet-dc.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -44,7 +43,7 @@ #include "transfer.h" #include "sysevents.h" #include "net.h" -#include "tiger.h" +#include /* * The Direct Connect protocol is extremely ugly. Thus, this code must @@ -158,6 +157,7 @@ static struct dcexppeer *expected = NULL; static char *hmlistname = NULL; static char *xmllistname = NULL; static char *xmlbz2listname = NULL; +static struct timer *listwritetimer = NULL; static void peerconnect(struct socket *sk, int err, struct fnetnode *fn); static void freedcpeer(struct dcpeer *peer); @@ -168,6 +168,7 @@ static void updatehmlist(void); static void updatexmllist(void); static void updatexmlbz2list(void); static void requestfile(struct dcpeer *peer); +static void updatelists(int now); static int reservedchar(unsigned char c) { @@ -726,7 +727,7 @@ static void requestfile(struct dcpeer *peer) freedcpeer(peer); return; } - qstrf(peer->sk, "$UGetBlock %i %i %s|", peer->transfer->curpos, peer->transfer->size - peer->transfer->curpos, buf); + qstrf(peer->sk, "$UGetBlock %zi %zi %s|", peer->transfer->curpos, peer->transfer->size - peer->transfer->curpos, buf); } else { /* Use DCCHARSET for $Get paths until further researched... */ if((buf = icswcstombs(peer->transfer->path, DCCHARSET, NULL)) == NULL) @@ -735,7 +736,7 @@ static void requestfile(struct dcpeer *peer) freedcpeer(peer); return; } - qstrf(peer->sk, "$Get %s$%i|", buf, peer->transfer->curpos + 1); + qstrf(peer->sk, "$Get %s$%zi|", buf, peer->transfer->curpos + 1); } } @@ -1017,7 +1018,7 @@ static void cmd_forcemove(struct socket *sk, struct fnetnode *fn, char *cmd, cha } else { freeargs = 0; } - if((newfn = fnetinitconnect(L"dc", args, NULL)) != NULL) + if((newfn = fnetinitconnect(L"dc", fn->owner, args, NULL)) != NULL) { linkfnetnode(newfn); putfnetnode(newfn); @@ -1083,7 +1084,8 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * struct sockaddr_in addr; struct sharecache *node; int minsize, maxsize; - int dotth, buflen; + int dotth; + size_t buflen; int termnum, satisfied, skipcheck; int level, tersat[32]; wchar_t *terms[32]; @@ -1166,10 +1168,11 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * if(!dotth && !strncmp(p, "TTH:", 4)) { dotth = 1; - if((buf = base32decode(p + 4, &buflen)) == NULL) - goto out; - if(buflen != 24) + if(((buf = base32decode(p + 4, &buflen)) == NULL) || (buflen != 24)) + { + free(buf); goto out; + } memcpy(hashtth, buf, 24); free(buf); } else { @@ -1227,10 +1230,10 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * if(node->f.b.hastth) { buf2 = base32encode(node->hashtth, 24); - qstrf(dsk, "%s%s\005%i%sTTH:%.39s%s", prefix, buf, node->size, infix, buf2, postfix); + qstrf(dsk, "%s%s\005%zi%sTTH:%.39s%s", prefix, buf, node->size, infix, buf2, postfix); free(buf2); } else { - qstrf(dsk, "%s%s\005%i%s%s%s", prefix, buf, node->size, infix, hub->nativename, postfix); + qstrf(dsk, "%s%s\005%zi%s%s%s", prefix, buf, node->size, infix, hub->nativename, postfix); } free(buf); } @@ -1308,7 +1311,7 @@ static void sendctm(struct socket *sk, char *nick) if(tcpsock == NULL) return; - if(sockgetremotename(tcpsock, &addr, &addrlen) < 0) + if(sockgetremotename2(tcpsock, sk, &addr, &addrlen) < 0) return; if(addr->sa_family == AF_INET) qstrf(sk, "$ConnectToMe %s %s|", nick, formataddress(addr, addrlen)); @@ -1543,6 +1546,11 @@ static void cmd_direction(struct socket *sk, struct dcpeer *peer, char *cmd, cha peer->direction = mydir; if(peer->direction == TRNSD_UP) { + if(confgetint("transfer", "ulquota") && hasupload(&dcnet, peer->wcsname)) + { + freedcpeer(peer); + return; + } transfer = newupload(peer->fn, &dcnet, peer->wcsname, &dctransfer, peer); } else { if((transfer = finddownload(peer->wcsname)) == NULL) @@ -1589,6 +1597,11 @@ static void cmd_peerlock(struct socket *sk, struct dcpeer *peer, char *cmd, char sendsupports(peer); if((transfer = finddownload(peer->wcsname)) == NULL) { + if(confgetint("transfer", "ulquota") && hasupload(&dcnet, peer->wcsname)) + { + freedcpeer(peer); + return; + } peer->direction = TRNSD_UP; transfer = newupload(peer->fn, &dcnet, peer->wcsname, &dctransfer, peer); } else { @@ -1600,6 +1613,7 @@ static void cmd_peerlock(struct socket *sk, struct dcpeer *peer, char *cmd, char peer->transfer = transfer; qstrf(sk, "$Direction %s %i|", (peer->direction == TRNSD_UP)?"Upload":"Download", rand() % 10000); qstrf(sk, "$Key %s|", key); + free(key); } else { if(peer->key != NULL) free(peer->key); @@ -1846,7 +1860,7 @@ static void cmd_get(struct socket *sk, struct dcpeer *peer, char *cmd, char *arg lesk = wrapsock(fd); transferprepul(peer->transfer, sb.st_size, offset, -1, lesk); putsock(lesk); - qstrf(sk, "$FileLength %i|", peer->transfer->size); + qstrf(sk, "$FileLength %zi|", peer->transfer->size); } static void cmd_send(struct socket *sk, struct dcpeer *peer, char *cmd, char *args) @@ -2412,8 +2426,10 @@ static struct hash *findsehash(struct sexpr *sexpr) return(h1); break; case SOP_OR: - h1 = findsehash(sexpr->l); - h2 = findsehash(sexpr->r); + if((h1 = findsehash(sexpr->l)) == NULL) + return(NULL); + if((h2 = findsehash(sexpr->r)) == NULL) + return(NULL); if(hashcmp(h1, h2)) return(h1); break; @@ -2516,7 +2532,7 @@ static int hubsearch(struct fnetnode *fn, struct search *srch, struct srchfnnlis addtobuf(sstr, 0); if(tcpsock != NULL) { - if(sockgetremotename(udpsock, &name, &namelen) < 0) + if(sockgetremotename2(udpsock, fn->sk, &name, &namelen) < 0) { flog(LOG_WARNING, "cannot get address of UDP socket"); } else { @@ -2537,7 +2553,7 @@ static int hubsearch(struct fnetnode *fn, struct search *srch, struct srchfnnlis #undef qstrf #define cc(c) ((void (*)(struct socket *, void *, char *, char *))(c)) -struct command hubcmds[] = +static struct command hubcmds[] = { {"$Lock", cc(cmd_lock)}, {"$HubName", cc(cmd_hubname)}, @@ -2560,7 +2576,7 @@ struct command hubcmds[] = {NULL, NULL} }; -struct command peercmds[] = +static struct command peercmds[] = { {"$MyNick", cc(cmd_mynick)}, {"$Lock", cc(cmd_peerlock)}, @@ -2596,7 +2612,7 @@ static void dctransgotdata(struct transfer *transfer, struct dcpeer *peer) { int ret; void *buf; - char outbuf[1024]; + unsigned char outbuf[1024]; z_stream *cstr; size_t bufsize; @@ -3077,6 +3093,8 @@ static void hubdestroy(struct fnetnode *fn) if((fn->sk != NULL) && (fn->sk->data == fn)) { fn->sk->data = NULL; + fn->sk->readcb = NULL; + fn->sk->errcb = NULL; putfnetnode(fn); } if(hub == NULL) @@ -3172,6 +3190,7 @@ static void peerconnect(struct socket *sk, int err, struct fnetnode *fn) if(err != 0) { putfnetnode(fn); + putsock(sk); return; } hub = fn->data; @@ -3227,7 +3246,7 @@ static void updatehmlist(void) if(node->f.b.type == FILE_REG) { addtobuf(buf, '|'); - sprintf(numbuf, "%i", node->size); + sprintf(numbuf, "%zi", node->size); bufcat(buf, numbuf, strlen(numbuf)); } addtobuf(buf, 13); @@ -3402,7 +3421,7 @@ static void updatexmllist(void) lev++; continue; } else { - fprintf(fs, "size); + fprintf(fs, "size); if(node->f.b.hastth) { hashbuf = base32encode(node->hashtth, 24); @@ -3498,11 +3517,33 @@ static void updatexmlbz2list(void) fclose(real); } -static int shareupdate(unsigned long long uusharesize, void *data) +static void listtimercb(int cancelled, void *uudata) { + listwritetimer = NULL; + if(!cancelled) + updatelists(1); +} + +static void updatelists(int now) +{ + if((hmlistname == NULL) || (xmllistname == NULL) || (xmlbz2listname == NULL)) + now = 1; + if(!now) + { + if(listwritetimer == NULL) + listwritetimer = timercallback(ntime() + confgetint("cli", "hashwritedelay"), listtimercb, NULL); + return; + } + if(listwritetimer != NULL) + canceltimer(listwritetimer); updatehmlist(); updatexmllist(); updatexmlbz2list(); +} + +static int shareupdate(unsigned long long uusharesize, void *data) +{ + updatelists(0); return(0); } @@ -3669,11 +3710,31 @@ static void terminate(void) static struct configvar myvars[] = { + /** Specifies the share description reported to other DC users. */ {CONF_VAR_STRING, "desc", {.str = L""}}, + /** Specifies the speed reported to other DC users. Normal values + * are 28.8Kbps, 33.6Kbps, 56Kbps, Satellite, ISDN, DSL, Cable, + * LAN(T1) or LAN(T3)*/ {CONF_VAR_STRING, "speedstring", {.str = L"LAN(T1)"}}, + /** The e-mail address to report to other DC users. */ {CONF_VAR_STRING, "email", {.str = L"spam@spam.org"}}, + /** Specifies a specific UDP port to use for DC search results. If + * left unspecified, a port is allocated dynamically. Useful for + * NAT routers (see also the net.visibleipv4 address for those + * cases). */ {CONF_VAR_INT, "udpport", {.num = 0}}, + /** Specifies a specific TCP port to use for DC peer + * connections. If left unspecified, a port is allocated + * dynamically. Useful for NAT routers (see also the + * net.visibleipv4 address for those cases). */ {CONF_VAR_INT, "tcpport", {.num = 0}}, + /** If set to true, doldacond will do its best to emulate DC++ + * (currently v0.674). This should be left off if at all possible, + * since turning it on will violate the rules of most hubs and + * thus give hub owners an actual reason to kick you if it is + * detected. It might be needed for some of the more bone-headed + * hub owners, though. Note that DC++ emulation can also be turned + * on or off for individual hubs, overriding this setting. */ {CONF_VAR_BOOL, "dcppemu", {.num = 0}}, {CONF_VAR_END} };