dc-filtercmd needs bash, not sh.
[doldaconnect.git] / daemon / search.h
CommitLineData
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
45struct wcslist
46{
47 struct wcslist *next, *prev;
48 wchar_t *str;
49 size_t len;
50};
51
52struct 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;
67 int n;
9d8cf743 68 struct hash *hash;
d3372da9 69 } d;
70};
71
72struct srchfnnlist
73{
74 struct srchfnnlist *next;
75 struct fnetnode *fn;
76 void *fnetdata;
77 CBCHAIN(searchfnl_destroy, struct srchfnnlist *ln);
78};
79
80struct 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
100struct srchres
101{
102 struct srchres *next, *prev;
103 struct search *srch;
104 wchar_t *filename;
105 struct fnet *fnet;
106 wchar_t *peerid, *peernick;
107 size_t size;
108 int slots;
109 struct fnetnode *fn;
110 double time;
1c7f7555 111 struct hash *hash;
d3372da9 112};
113
114wchar_t *regexunquotesimple(wchar_t *re);
115struct sexpr *parsesexpr(int argc, wchar_t **argv);
116void optsexpr(struct sexpr *sexpr);
117void getsexpr(struct sexpr *sexpr);
118void putsexpr(struct sexpr *sexpr);
119struct search *newsearch(wchar_t *owner, struct sexpr *sexpr);
120void searchaddfn(struct search *srch, struct fnetnode *fn);
121void queuesearch(struct search *srch);
122void freesearch(struct search *srch);
123struct wcslist *regexfindstrings(wchar_t *re);
124void freesl(struct wcslist **list);
125void slmergemax(struct wcslist **dest, struct wcslist *src);
126struct wcslist *slmergemin(struct wcslist *l1, struct wcslist *l2);
127struct wcslist *findsexprstrs(struct sexpr *sexpr);
128struct srchres *newsrchres(struct fnet *fnet, wchar_t *filename, wchar_t *peerid);
129void freesrchres(struct srchres *sr);
130void submitsrchres(struct srchres *sr);
131struct search *findsearch(int id);
132
133extern struct search *searches;
134EGCBCHAIN(newsrchcb, struct search *);
135
136#endif