Change default hub list.
[doldaconnect.git] / daemon / search.c
index 040ec30..d16e5a0 100644 (file)
@@ -32,6 +32,7 @@
 #include "log.h"
 #include "sysevents.h"
 #include "filenet.h"
+#include "client.h"
 #include "search.h"
 
 #define TOK_STR 0
@@ -514,6 +515,11 @@ void putsexpr(struct sexpr *sexpr)
        if(sexpr->d.s != NULL)
            free(sexpr->d.s);
     }
+    if(sexpr->op == SOP_HASHIS)
+    {
+       if(sexpr->d.hash != NULL)
+           freehash(sexpr->d.hash);
+    }
     free(sexpr);
 }
 
@@ -648,6 +654,23 @@ struct sexpr *parsesexpr(int argc, wchar_t **argv)
                freetok(tok2);
                putsexpr(sexpr);
                done = 0;
+           } else if((st->type == TOK_STR) && !wcsncmp(st->d.str, L"H=", 2)) {
+               tok2 = poptok(&st);
+               pushtok(tok = newtok(), &st);
+               tok->type = TOK_SE;
+               sexpr = newsexpr();
+               sexpr->op = SOP_HASHIS;
+               if((sexpr->d.hash = parsehash(tok2->d.str + 2)) == NULL)
+               {
+                   freetok(tok2);
+                   putsexpr(sexpr);
+                   goto out_err;
+               }
+               sexpr->cost = 2;
+               getsexpr(tok->d.se = sexpr);
+               freetok(tok2);
+               putsexpr(sexpr);
+               done = 0;
            } else if((std >= 3) && (st->type == TOK_CP) && (st->next->type == TOK_SE) && (st->next->next->type == TOK_OP)) {
                freetok(poptok(&st));
                tok = poptok(&st);
@@ -741,8 +764,6 @@ struct wcslist *findsexprstrs(struct sexpr *sexpr)
        freesl(&l1);
        freesl(&l2);
        break;
-    case SOP_NOT:
-       break;
     case SOP_NAMERE:
     case SOP_LINKRE:
        list = regexfindstrings(sexpr->d.re.sre);
@@ -1082,6 +1103,10 @@ static int srisvalid(struct srchres *sr, struct sexpr *sexpr)
        return(sr->size == sexpr->d.n);
     case SOP_SIZEGT:
        return(sr->size > sexpr->d.n);
+    case SOP_HASHIS:
+       if(sr->hash == NULL)
+           return(0);
+       return(hashcmp(sr->hash, sexpr->d.hash));
     }
     return(0);
 }
@@ -1112,6 +1137,8 @@ void freesrchres(struct srchres *sr)
            sr->srch->results = sr->next;
        sr->srch->numres--;
     }
+    if(sr->hash != NULL)
+       freehash(sr->hash);
     if(sr->filename != NULL)
        free(sr->filename);
     if(sr->peerid != NULL)
@@ -1140,6 +1167,8 @@ struct srchres *dupsrchres(struct srchres *sr)
        new->filename = swcsdup(sr->filename);
     if(sr->fn != NULL)
        getfnetnode(new->fn = sr->fn);
+    if(sr->hash != NULL)
+       new->hash = duphash(sr->hash);
     return(new);
 }