X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ffnet-dc.c;h=5123c8075231f48428e2404b1edcc3b55d33f593;hb=c662029bed19d3b706cee02ac093758e4cc99649;hp=0e035fed7090914b45d8c226f589169492e55775;hpb=9c161e776f0aa97d4cea5af7a0de070a6cc428d7;p=doldaconnect.git diff --git a/daemon/fnet-dc.c b/daemon/fnet-dc.c index 0e035fe..5123c80 100644 --- a/daemon/fnet-dc.c +++ b/daemon/fnet-dc.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -59,24 +60,6 @@ * considering it was developed without i18n support under Windows */ #define DCCHARSET "windows-1252" -#ifdef DCPP_MASQUERADE -/* - * I honestly don't want to pretend being a client that I'm not, but - * there are so many hubs that simply do not accept any clients - * outside their whitelists, for no obvious reasons, so I feel that I - * am left with little choice. Anyhow, as long as I actually support - * all the features that my faked DC++ version does, there should be - * very little harm done. - */ -#define DCIDTAG "++" -#define DCIDTAGV "0.674" -#define DCIDFULL "DC++ 0.674" -#else -#define DCIDTAG "Dolda" -#define DCIDTAGV VERSION -#define DCIDFULL "DoldaConnect " VERSION -#endif - #define PEER_CMD 0 #define PEER_STOP 1 #define PEER_TRNS 2 @@ -1141,7 +1124,7 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * size_t buflen; int termnum, satisfied, skipcheck; int level, tersat[32]; - wchar_t *terms[32]; + wchar_t *terms[32], *lname; char hashtth[24]; hub = fn->data; @@ -1229,8 +1212,10 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * memcpy(hashtth, buf, 24); free(buf); } else { - if((terms[termnum] = icmbstowcs(p, hub->charset)) != NULL) + if((terms[termnum] = icmbstowcs(p, hub->charset)) != NULL) { + wcslower(terms[termnum]); termnum++; + } } } p = p2 + 1; @@ -1262,11 +1247,12 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * } if(!skipcheck) { + lname = wcslower(swcsdup(node->name)); for(i = 0; i < termnum; i++) { if(tersat[i] >= 0) continue; - if(wcsexists(node->name, terms[i])) + if(wcsstr(lname, terms[i])) { tersat[i] = level; satisfied++; @@ -1274,6 +1260,7 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * break; } } + free(lname); } if(!skipcheck && (satisfied == termnum)) { @@ -2130,6 +2117,7 @@ static void cmd_adcget(struct socket *sk, struct dcpeer *peer, char *cmd, char * } 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) @@ -3014,7 +3002,7 @@ static void hubread(struct socket *sk, struct fnetnode *fn) free(newbuf); p = hub->inbuf; hub->inbufdata += datalen; - while((datalen > 0) && ((p2 = memchr(p, '|', datalen)) != NULL)) + while((p - hub->inbuf < hub->inbufdata) && ((p2 = memchr(p, '|', hub->inbufdata - (p - hub->inbuf))) != NULL)) { *(p2++) = 0; for(cmd = hubcmds; cmd->handler != NULL; cmd++) @@ -3025,7 +3013,6 @@ static void hubread(struct socket *sk, struct fnetnode *fn) } if((cmd->limit == 0) || (hub->queue.size < cmd->limit)) newqcmd(&hub->queue, p); - datalen -= p2 - p; p = p2; } memmove(hub->inbuf, p, hub->inbufdata -= p - hub->inbuf); @@ -3140,7 +3127,6 @@ static void freedcpeer(struct dcpeer *peer) peer->transfer->close = 1; if(peer->transfer->dir == TRNSD_DOWN) resettransfer(peer->transfer); - transferdetach(peer->transfer); } if(peer->timeout != NULL) canceltimer(peer->timeout); @@ -3336,6 +3322,7 @@ static void updatehmlist(void) char *buf, *buf2, numbuf[32]; size_t bufsize, bufdata; int fd, ibuf; + FILE *out; bufdata = 0; buf = smalloc(bufsize = 65536); @@ -3393,27 +3380,28 @@ static void updatehmlist(void) free(hmlistname); hmlistname = NULL; } else { + out = fdopen(fd, "w"); /* * I do not want to implement a good Huffman encoder, and it's not * like Huffman encoding actually yields any impressive results * for DC file lists anyway, so I'll just output a bogus * tree. Implement a good encoder if you want to. */ - write(fd, "HE3\r\0", 5); - write(fd, &bufdata, 4); + fwrite("HE3\r\0", 1, 5, out); + fwrite(&bufdata, 4, 1, out); /* XXX: Endian unsafe */ ibuf = 256; - write(fd, &ibuf, 2); + fwrite(&ibuf, 2, 1, out); ibuf = 8; for(i = 0; i < 256; i++) { - write(fd, &i, 1); - write(fd, &ibuf, 1); + fwrite(&i, 1, 1, out); + fwrite(&ibuf, 1, 1, out); } for(i = 0; i < 256; i++) - write(fd, &i, 1); + fwrite(&i, 1, 1, out); for(buf2 = buf; bufdata > 0;) { - if((ret = write(fd, buf2, bufdata)) < 0) + if((ret = fwrite(buf2, 1, bufdata, out)) < 0) { flog(LOG_WARNING, "could not write file list: %s", strerror(errno)); break; @@ -3421,7 +3409,7 @@ static void updatehmlist(void) bufdata -= ret; buf2 += ret; } - close(fd); + fclose(out); } free(buf); }