d3372da9 |
1 | /* |
2 | * Dolda Connect - Modular multiuser Direct Connect-style client |
302a2600 |
3 | * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com> |
d3372da9 |
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 | |
1c7f7555 |
22 | #include "client.h" |
d3372da9 |
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 |
9d8cf743 |
40 | #define SOP_HASHIS 12 |
d3372da9 |
41 | |
42 | #define SRCH_WAIT 0 |
43 | #define SRCH_RUN 1 |
44 | |
45 | struct wcslist |
46 | { |
47 | struct wcslist *next, *prev; |
48 | wchar_t *str; |
49 | size_t len; |
50 | }; |
51 | |
52 | struct sexpr |
53 | { |
54 | int refcount; |
55 | int op; |
56 | struct sexpr *l, *r; |
57 | int cost, tcost; |
58 | union |
59 | { |
60 | struct |
61 | { |
62 | wchar_t *sre; |
63 | regex_t cre; |
64 | int inited; |
65 | } re; |
66 | wchar_t *s; |
4e564b59 |
67 | off_t sz; |
9d8cf743 |
68 | struct hash *hash; |
d3372da9 |
69 | } d; |
70 | }; |
71 | |
72 | struct srchfnnlist |
73 | { |
74 | struct srchfnnlist *next; |
75 | struct fnetnode *fn; |
76 | void *fnetdata; |
77 | CBCHAIN(searchfnl_destroy, struct srchfnnlist *ln); |
78 | }; |
79 | |
80 | struct search |
81 | { |
82 | struct search *next, *prev; |
83 | int id; |
84 | int state; |
85 | wchar_t *owner; |
86 | int prio; |
87 | time_t eta; |
88 | double committime; |
89 | struct sexpr *sexpr; |
90 | struct srchfnnlist *fnl; |
91 | struct srchres *results; |
92 | int numres; |
93 | struct timer *freetimer; |
94 | CBCHAIN(search_eta, struct search *srch); |
95 | CBCHAIN(search_commit, struct search *srch); |
96 | CBCHAIN(search_result, struct search *srch, struct srchres *sr); |
97 | CBCHAIN(search_destroy, struct search *srch); |
98 | }; |
99 | |
100 | struct srchres |
101 | { |
102 | struct srchres *next, *prev; |
103 | struct search *srch; |
104 | wchar_t *filename; |
105 | struct fnet *fnet; |
106 | wchar_t *peerid, *peernick; |
dcf7a1a2 |
107 | off_t size; |
d3372da9 |
108 | int slots; |
109 | struct fnetnode *fn; |
110 | double time; |
1c7f7555 |
111 | struct hash *hash; |
d3372da9 |
112 | }; |
113 | |
114 | wchar_t *regexunquotesimple(wchar_t *re); |
115 | struct sexpr *parsesexpr(int argc, wchar_t **argv); |
116 | void optsexpr(struct sexpr *sexpr); |
117 | void getsexpr(struct sexpr *sexpr); |
118 | void putsexpr(struct sexpr *sexpr); |
119 | struct search *newsearch(wchar_t *owner, struct sexpr *sexpr); |
120 | void searchaddfn(struct search *srch, struct fnetnode *fn); |
121 | void queuesearch(struct search *srch); |
122 | void freesearch(struct search *srch); |
123 | struct wcslist *regexfindstrings(wchar_t *re); |
124 | void freesl(struct wcslist **list); |
125 | void slmergemax(struct wcslist **dest, struct wcslist *src); |
126 | struct wcslist *slmergemin(struct wcslist *l1, struct wcslist *l2); |
127 | struct wcslist *findsexprstrs(struct sexpr *sexpr); |
128 | struct srchres *newsrchres(struct fnet *fnet, wchar_t *filename, wchar_t *peerid); |
129 | void freesrchres(struct srchres *sr); |
130 | void submitsrchres(struct srchres *sr); |
131 | struct search *findsearch(int id); |
132 | |
133 | extern struct search *searches; |
134 | EGCBCHAIN(newsrchcb, struct search *); |
135 | |
136 | #endif |