Add hash attribute to SRs.
[doldaconnect.git] / daemon / search.h
1 /*
2  *  Dolda Connect - Modular multiuser Direct Connect-style client
3  *  Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
4  *  
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *  
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *  
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19 #ifndef _SEARCH_H
20 #define _SEARCH_H
21
22 #include "client.h"
23 #include "filenet.h"
24 #include "sysevents.h"
25 #include <regex.h>
26 #include <wchar.h>
27
28 #define SOP_FALSE 0
29 #define SOP_TRUE 1
30 #define SOP_AND 2
31 #define SOP_OR 3
32 #define SOP_NOT 4
33 #define SOP_NAMERE 5
34 #define SOP_NAMESS 6
35 #define SOP_LINKRE 7
36 #define SOP_LINKSS 8
37 #define SOP_SIZEGT 9
38 #define SOP_SIZELT 10
39 #define SOP_SIZEEQ 11
40
41 #define SRCH_WAIT 0
42 #define SRCH_RUN 1
43
44 struct wcslist
45 {
46     struct wcslist *next, *prev;
47     wchar_t *str;
48     size_t len;
49 };
50
51 struct sexpr
52 {
53     int refcount;
54     int op;
55     struct sexpr *l, *r;
56     int cost, tcost;
57     union
58     {
59         struct
60         {
61             wchar_t *sre;
62             regex_t cre;
63             int inited;
64         } re;
65         wchar_t *s;
66         int n;
67     } d;
68 };
69
70 struct srchfnnlist
71 {
72     struct srchfnnlist *next;
73     struct fnetnode *fn;
74     void *fnetdata;
75     CBCHAIN(searchfnl_destroy, struct srchfnnlist *ln);
76 };
77
78 struct search
79 {
80     struct search *next, *prev;
81     int id;
82     int state;
83     wchar_t *owner;
84     int prio;
85     time_t eta;
86     double committime;
87     struct sexpr *sexpr;
88     struct srchfnnlist *fnl;
89     struct srchres *results;
90     int numres;
91     struct timer *freetimer;
92     CBCHAIN(search_eta, struct search *srch);
93     CBCHAIN(search_commit, struct search *srch);
94     CBCHAIN(search_result, struct search *srch, struct srchres *sr);
95     CBCHAIN(search_destroy, struct search *srch);
96 };
97
98 struct srchres
99 {
100     struct srchres *next, *prev;
101     struct search *srch;
102     wchar_t *filename;
103     struct fnet *fnet;
104     wchar_t *peerid, *peernick;
105     size_t size;
106     int slots;
107     struct fnetnode *fn;
108     double time;
109     struct hash *hash;
110 };
111
112 wchar_t *regexunquotesimple(wchar_t *re);
113 struct sexpr *parsesexpr(int argc, wchar_t **argv);
114 void optsexpr(struct sexpr *sexpr);
115 void getsexpr(struct sexpr *sexpr);
116 void putsexpr(struct sexpr *sexpr);
117 struct search *newsearch(wchar_t *owner, struct sexpr *sexpr);
118 void searchaddfn(struct search *srch, struct fnetnode *fn);
119 void queuesearch(struct search *srch);
120 void freesearch(struct search *srch);
121 struct wcslist *regexfindstrings(wchar_t *re);
122 void freesl(struct wcslist **list);
123 void slmergemax(struct wcslist **dest, struct wcslist *src);
124 struct wcslist *slmergemin(struct wcslist *l1, struct wcslist *l2);
125 struct wcslist *findsexprstrs(struct sexpr *sexpr);
126 struct srchres *newsrchres(struct fnet *fnet, wchar_t *filename, wchar_t *peerid);
127 void freesrchres(struct srchres *sr);
128 void submitsrchres(struct srchres *sr);
129 struct search *findsearch(int id);
130
131 extern struct search *searches;
132 EGCBCHAIN(newsrchcb, struct search *);
133
134 #endif