libwebsockets
Lightweight C library for HTML5 websockets
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
34struct lws_fts;
35struct 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
72 int matches; /* logical number of matches */
73 int matches_length; /* bytes in length table (may be zero) */
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
89 char elided; /* children skipped in interest of antecedent 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 */
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
119LWS_VISIBLE LWS_EXTERN struct lws_fts *
121
131lws_fts_destroy(struct lws_fts **trie);
132
144lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len,
145 int priority);
146
163lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf,
164 size_t len);
165
176lws_fts_serialize(struct lws_fts *t);
177
178/*
179 * index search functions
180 */
181
190LWS_VISIBLE LWS_EXTERN struct lws_fts_file *
191lws_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
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 */
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 */
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 */
222};
223
244lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp);
245
254lws_fts_close(struct lws_fts_file *jtf);
255
struct lws_fts_result_filepath * next
Definition lws-fts.h:71
struct lwsac * results_head
Definition lws-fts.h:204
const char * only_filepath
Definition lws-fts.h:202
struct lws_fts_result_autocomplete * next
Definition lws-fts.h:85
const char * needle
Definition lws-fts.h:200
int effective_flags
Definition lws-fts.h:104
struct lws_fts_result_filepath * filepath_head
Definition lws-fts.h:101
struct lws_fts_result_autocomplete * autocomplete_head
Definition lws-fts.h:102
LWS_VISIBLE LWS_EXTERN struct lws_fts_file * lws_fts_open(const char *filepath)
LWS_VISIBLE LWS_EXTERN int lws_fts_serialize(struct lws_fts *t)
LWS_VISIBLE LWS_EXTERN void lws_fts_destroy(struct lws_fts **trie)
LWS_VISIBLE LWS_EXTERN int lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len, int priority)
LWS_VISIBLE LWS_EXTERN struct lws_fts_result * lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp)
LWS_VISIBLE LWS_EXTERN struct lws_fts * lws_fts_create(int fd)
LWS_VISIBLE LWS_EXTERN int lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, size_t len)
LWS_VISIBLE LWS_EXTERN void lws_fts_close(struct lws_fts_file *jtf)
unsigned int uint32_t
#define LWS_EXTERN
#define LWS_VISIBLE