Add trivial HM decoder
[doldaconnect.git] / daemon / search.h
CommitLineData
d3372da9 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 "filenet.h"
23#include "sysevents.h"
24#include <regex.h>
25#include <wchar.h>
26
27#define SOP_FALSE 0
28#define SOP_TRUE 1
29#define SOP_AND 2
30#define SOP_OR 3
31#define SOP_NOT 4
32#define SOP_NAMERE 5
33#define SOP_NAMESS 6
34#define SOP_LINKRE 7
35#define SOP_LINKSS 8
36#define SOP_SIZEGT 9
37#define SOP_SIZELT 10
38#define SOP_SIZEEQ 11
39
40#define SRCH_WAIT 0
41#define SRCH_RUN 1
42
43struct wcslist
44{
45 struct wcslist *next, *prev;
46 wchar_t *str;
47 size_t len;
48};
49
50struct sexpr
51{
52 int refcount;
53 int op;
54 struct sexpr *l, *r;
55 int cost, tcost;
56 union
57 {
58 struct
59 {
60 wchar_t *sre;
61 regex_t cre;
62 int inited;
63 } re;
64 wchar_t *s;
65 int n;
66 } d;
67};
68
69struct srchfnnlist
70{
71 struct srchfnnlist *next;
72 struct fnetnode *fn;
73 void *fnetdata;
74 CBCHAIN(searchfnl_destroy, struct srchfnnlist *ln);
75};
76
77struct search
78{
79 struct search *next, *prev;
80 int id;
81 int state;
82 wchar_t *owner;
83 int prio;
84 time_t eta;
85 double committime;
86 struct sexpr *sexpr;
87 struct srchfnnlist *fnl;
88 struct srchres *results;
89 int numres;
90 struct timer *freetimer;
91 CBCHAIN(search_eta, struct search *srch);
92 CBCHAIN(search_commit, struct search *srch);
93 CBCHAIN(search_result, struct search *srch, struct srchres *sr);
94 CBCHAIN(search_destroy, struct search *srch);
95};
96
97struct srchres
98{
99 struct srchres *next, *prev;
100 struct search *srch;
101 wchar_t *filename;
102 struct fnet *fnet;
103 wchar_t *peerid, *peernick;
104 size_t size;
105 int slots;
106 struct fnetnode *fn;
107 double time;
108};
109
110wchar_t *regexunquotesimple(wchar_t *re);
111struct sexpr *parsesexpr(int argc, wchar_t **argv);
112void optsexpr(struct sexpr *sexpr);
113void getsexpr(struct sexpr *sexpr);
114void putsexpr(struct sexpr *sexpr);
115struct search *newsearch(wchar_t *owner, struct sexpr *sexpr);
116void searchaddfn(struct search *srch, struct fnetnode *fn);
117void queuesearch(struct search *srch);
118void freesearch(struct search *srch);
119struct wcslist *regexfindstrings(wchar_t *re);
120void freesl(struct wcslist **list);
121void slmergemax(struct wcslist **dest, struct wcslist *src);
122struct wcslist *slmergemin(struct wcslist *l1, struct wcslist *l2);
123struct wcslist *findsexprstrs(struct sexpr *sexpr);
124struct srchres *newsrchres(struct fnet *fnet, wchar_t *filename, wchar_t *peerid);
125void freesrchres(struct srchres *sr);
126void submitsrchres(struct srchres *sr);
127struct search *findsearch(int id);
128
129extern struct search *searches;
130EGCBCHAIN(newsrchcb, struct search *);
131
132#endif