X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ffnet-dc.c;h=3dbb81fe6b5fbf7cf60124aab6c4596f6ebc4c05;hb=c8c6be241f782e0d3fecb0fbfb042fd28a3f5dad;hp=b79e84d193d9ac7e1128d494872025c0042690c0;hpb=7a00b8b0d81ccb8dc60b3482978b0aa5e7ddfc55;p=doldaconnect.git diff --git a/daemon/fnet-dc.c b/daemon/fnet-dc.c index b79e84d..3dbb81f 100644 --- a/daemon/fnet-dc.c +++ b/daemon/fnet-dc.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -1123,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; @@ -1211,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; @@ -1244,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++; @@ -1256,6 +1260,7 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * break; } } + free(lname); } if(!skipcheck && (satisfied == termnum)) { @@ -3316,6 +3321,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); @@ -3373,27 +3379,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; @@ -3401,7 +3408,7 @@ static void updatehmlist(void) bufdata -= ret; buf2 += ret; } - close(fd); + fclose(out); } free(buf); }