libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
Loading...
Searching...
No Matches
lws-fts.h
Go to the documentation of this file.
1
/*
2
* libwebsockets - small server side websockets and web server implementation
3
*
4
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to
8
* deal in the Software without restriction, including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
* sell copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
* IN THE SOFTWARE.
23
*/
24
33
34
struct
lws_fts;
35
struct
lws_fts_file;
36
37
/*
38
* Queries produce their results in an lwsac, using these public API types.
39
* The first thing in the lwsac is always a struct lws_fts_result (see below)
40
* containing heads for linked-lists of the other result types.
41
*/
42
43
/* one filepath's results */
44
45
/*
46
* Immediately after the struct comes the match table, then the filepath
47
* string (of filepath_length, NUL-terminated); .matches_length is the number
48
* of bytes in the match table, so the filepath is always at
49
* ((char *)&fp[1]) + fp->matches_length.
50
*
51
* The match table holds exactly .matches fixed-size records, in this order,
52
* with no padding and no omissions:
53
*
54
* - nothing at all, if LWSFTS_F_QUERY_FILE_LINES was not given
55
*
56
* - uint32_t line number, uint32_t byte offset of that line in the original
57
* file, if LWSFTS_F_QUERY_FILE_LINES was given
58
*
59
* - the two uint32_t above, then a const char * to a NUL-terminated quote of
60
* the line (also in the results lwsac), if LWSFTS_F_QUERY_QUOTE_LINE was
61
* also given
62
*
63
* The stride is fixed: if the library could not resolve a particular match
64
* (eg, the original file has changed since it was indexed), that record is
65
* present but zero, ie, the offset is 0 and the quote pointer is NULL.
66
* Consumers must be ready for a NULL quote pointer, but may rely on the
67
* record count and stride.
68
*/
69
70
struct
lws_fts_result_filepath
{
71
struct
lws_fts_result_filepath
*
next
;
72
int
matches
;
/* logical number of matches */
73
int
matches_length
;
/* bytes in length table (may be zero) */
74
int
lines_in_file
;
75
int
filepath_length
;
76
char
truncated
;
/* there were more matches, capped by max_lines */
77
78
/* - uint32_t line table follows (first for alignment) */
79
/* - filepath (of filepath_length) follows */
80
};
81
82
/* autocomplete result */
83
84
struct
lws_fts_result_autocomplete
{
85
struct
lws_fts_result_autocomplete
*
next
;
86
int
instances
;
87
int
agg_instances
;
88
int
ac_length
;
89
char
elided
;
/* children skipped in interest of antecedent children */
90
char
has_children
;
91
92
/* - autocomplete suggestion (of length ac_length) follows */
93
};
94
95
/*
96
* The results lwsac always starts with this. If no results and / or no
97
* autocomplete the members may be NULL. This implies the symbol nor any
98
* suffix on it exists in the trie file.
99
*/
100
struct
lws_fts_result
{
101
struct
lws_fts_result_filepath
*
filepath_head
;
102
struct
lws_fts_result_autocomplete
*
autocomplete_head
;
103
int
duration_ms
;
104
int
effective_flags
;
/* the search flags that were used */
105
char
truncated
;
/* there were more filepaths, capped by max_files */
106
};
107
108
/*
109
* index creation functions
110
*/
111
119
LWS_VISIBLE
LWS_EXTERN
struct
lws_fts *
120
lws_fts_create
(
int
fd);
121
130
LWS_VISIBLE
LWS_EXTERN
void
131
lws_fts_destroy
(
struct
lws_fts **trie);
132
143
LWS_VISIBLE
LWS_EXTERN
int
144
lws_fts_file_index
(
struct
lws_fts *t,
const
char
*filepath,
int
filepath_len,
145
int
priority);
146
162
LWS_VISIBLE
LWS_EXTERN
int
163
lws_fts_fill
(
struct
lws_fts *t,
uint32_t
file_index,
const
char
*buf,
164
size_t
len);
165
175
LWS_VISIBLE
LWS_EXTERN
int
176
lws_fts_serialize
(
struct
lws_fts *t);
177
178
/*
179
* index search functions
180
*/
181
190
LWS_VISIBLE
LWS_EXTERN
struct
lws_fts_file *
191
lws_fts_open
(
const
char
*filepath);
192
193
#define LWSFTS_F_QUERY_AUTOCOMPLETE (1 << 0)
194
#define LWSFTS_F_QUERY_FILES (1 << 1)
195
#define LWSFTS_F_QUERY_FILE_LINES (1 << 2)
196
#define LWSFTS_F_QUERY_QUOTE_LINE (1 << 3)
197
198
struct
lws_fts_search_params
{
199
/* the actual search term */
200
const
char
*
needle
;
201
/* if non-NULL, FILE results for this filepath only */
202
const
char
*
only_filepath
;
203
/* will be set to the results lwsac */
204
struct
lwsac *
results_head
;
205
/* combination of LWSFTS_F_QUERY_* flags */
206
int
flags
;
207
/* maximum number of autocomplete suggestions to return */
208
int
max_autocomplete
;
209
/*
210
* Maximum number of filepaths to return, 0 = no limit. If the walk
211
* stopped here, result.truncated is set. Any caller acting on an
212
* untrusted needle should set this: a one-character needle otherwise
213
* walks the whole indexed corpus into the results lwsac.
214
*/
215
int
max_files
;
216
/*
217
* Maximum number of line number results to return per filepath, 0 =
218
* no limit (there is still an internal ceiling). If a filepath's
219
* results stopped here, that filepath result's .truncated is set.
220
*/
221
int
max_lines
;
222
};
223
243
LWS_VISIBLE
LWS_EXTERN
struct
lws_fts_result
*
244
lws_fts_search
(
struct
lws_fts_file *jtf,
struct
lws_fts_search_params
*ftsp);
245
253
LWS_VISIBLE
LWS_EXTERN
void
254
lws_fts_close
(
struct
lws_fts_file *jtf);
255
lws_fts_result_filepath::next
struct lws_fts_result_filepath * next
Definition
lws-fts.h:71
lws_fts_search_params::max_files
int max_files
Definition
lws-fts.h:215
lws_fts_result_autocomplete::ac_length
int ac_length
Definition
lws-fts.h:88
lws_fts_search_params::results_head
struct lwsac * results_head
Definition
lws-fts.h:204
lws_fts_result_autocomplete::agg_instances
int agg_instances
Definition
lws-fts.h:87
lws_fts_search_params::max_autocomplete
int max_autocomplete
Definition
lws-fts.h:208
lws_fts_result_filepath::truncated
char truncated
Definition
lws-fts.h:76
lws_fts_search_params::only_filepath
const char * only_filepath
Definition
lws-fts.h:202
lws_fts_result_autocomplete::next
struct lws_fts_result_autocomplete * next
Definition
lws-fts.h:85
lws_fts_search_params::needle
const char * needle
Definition
lws-fts.h:200
lws_fts_result_filepath::matches
int matches
Definition
lws-fts.h:72
lws_fts_search_params::flags
int flags
Definition
lws-fts.h:206
lws_fts_result_filepath::filepath_length
int filepath_length
Definition
lws-fts.h:75
lws_fts_result_filepath::lines_in_file
int lines_in_file
Definition
lws-fts.h:74
lws_fts_result_autocomplete::instances
int instances
Definition
lws-fts.h:86
lws_fts_result::effective_flags
int effective_flags
Definition
lws-fts.h:104
lws_fts_result::filepath_head
struct lws_fts_result_filepath * filepath_head
Definition
lws-fts.h:101
lws_fts_result::truncated
char truncated
Definition
lws-fts.h:105
lws_fts_result_autocomplete::elided
char elided
Definition
lws-fts.h:89
lws_fts_search_params::max_lines
int max_lines
Definition
lws-fts.h:221
lws_fts_result_filepath::matches_length
int matches_length
Definition
lws-fts.h:73
lws_fts_result_autocomplete::has_children
char has_children
Definition
lws-fts.h:90
lws_fts_result::autocomplete_head
struct lws_fts_result_autocomplete * autocomplete_head
Definition
lws-fts.h:102
lws_fts_result::duration_ms
int duration_ms
Definition
lws-fts.h:103
lws_fts_open
LWS_VISIBLE LWS_EXTERN struct lws_fts_file * lws_fts_open(const char *filepath)
lws_fts_serialize
LWS_VISIBLE LWS_EXTERN int lws_fts_serialize(struct lws_fts *t)
lws_fts_destroy
LWS_VISIBLE LWS_EXTERN void lws_fts_destroy(struct lws_fts **trie)
lws_fts_file_index
LWS_VISIBLE LWS_EXTERN int lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len, int priority)
lws_fts_search
LWS_VISIBLE LWS_EXTERN struct lws_fts_result * lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp)
lws_fts_create
LWS_VISIBLE LWS_EXTERN struct lws_fts * lws_fts_create(int fd)
lws_fts_fill
LWS_VISIBLE LWS_EXTERN int lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, size_t len)
lws_fts_close
LWS_VISIBLE LWS_EXTERN void lws_fts_close(struct lws_fts_file *jtf)
lws_fts_result
Definition
lws-fts.h:100
lws_fts_result_autocomplete
Definition
lws-fts.h:84
lws_fts_result_filepath
Definition
lws-fts.h:70
lws_fts_search_params
Definition
lws-fts.h:198
uint32_t
unsigned int uint32_t
Definition
libwebsockets.h:744
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:327
LWS_VISIBLE
#define LWS_VISIBLE
Definition
libwebsockets.h:322
include
libwebsockets
lws-fts.h
Generated on
for libwebsockets by
1.18.0