]> git.notmuchmail.org Git - notmuch/blob - lib/notmuch-private.h
Merge tag 'debian/0.29.2-2'
[notmuch] / lib / notmuch-private.h
1 /* notmuch-private.h - Internal interfaces for notmuch.
2  *
3  * Copyright © 2009 Carl Worth
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 3 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, see https://www.gnu.org/licenses/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #ifndef NOTMUCH_PRIVATE_H
22 #define NOTMUCH_PRIVATE_H
23
24 #ifndef _GNU_SOURCE
25 #define _GNU_SOURCE /* For getline and asprintf */
26 #endif
27 #include <stdbool.h>
28 #include <stdio.h>
29
30 #include "compat.h"
31
32 #include "notmuch.h"
33
34 NOTMUCH_BEGIN_DECLS
35
36 #include <stdlib.h>
37 #include <stdarg.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <sys/mman.h>
41 #include <string.h>
42 #include <errno.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45 #include <ctype.h>
46 #include <assert.h>
47
48 #include <talloc.h>
49
50 #include "gmime-extra.h"
51
52 #include "xutil.h"
53 #include "error_util.h"
54 #include "string-util.h"
55 #include "crypto.h"
56 #include "repair.h"
57
58 #ifdef DEBUG
59 # define DEBUG_DATABASE_SANITY 1
60 # define DEBUG_THREADING 1
61 # define DEBUG_QUERY 1
62 #endif
63
64 #define COMPILE_TIME_ASSERT(pred) ((void) sizeof (char[1 - 2 * ! (pred)]))
65
66 #define STRNCMP_LITERAL(var, literal) \
67     strncmp ((var), (literal), sizeof (literal) - 1)
68
69 /* Robust bit test/set/reset macros */
70 #define _NOTMUCH_VALID_BIT(bit) \
71     ((bit) >= 0 && ((unsigned long) bit) < CHAR_BIT * sizeof (unsigned long long))
72 #define NOTMUCH_TEST_BIT(val, bit) \
73     (_NOTMUCH_VALID_BIT (bit) ? ! ! ((val) & (1ull << (bit))) : 0)
74 #define NOTMUCH_SET_BIT(valp, bit) \
75     (_NOTMUCH_VALID_BIT (bit) ? (*(valp) |= (1ull << (bit))) : *(valp))
76 #define NOTMUCH_CLEAR_BIT(valp,  bit) \
77     (_NOTMUCH_VALID_BIT (bit) ? (*(valp) &= ~(1ull << (bit))) : *(valp))
78
79 #define unused(x) x __attribute__ ((unused))
80
81 /* Thanks to Andrew Tridgell's (SAMBA's) talloc for this definition of
82  * unlikely. The talloc source code comes to us via the GNU LGPL v. 3.
83  */
84 /* these macros gain us a few percent of speed on gcc */
85 #if (__GNUC__ >= 3)
86 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
87  * as its first argument */
88 #ifndef likely
89 #define likely(x)   __builtin_expect (! ! (x), 1)
90 #endif
91 #ifndef unlikely
92 #define unlikely(x) __builtin_expect (! ! (x), 0)
93 #endif
94 #else
95 #ifndef likely
96 #define likely(x) (x)
97 #endif
98 #ifndef unlikely
99 #define unlikely(x) (x)
100 #endif
101 #endif
102
103 typedef enum {
104     NOTMUCH_VALUE_TIMESTAMP = 0,
105     NOTMUCH_VALUE_MESSAGE_ID,
106     NOTMUCH_VALUE_FROM,
107     NOTMUCH_VALUE_SUBJECT,
108     NOTMUCH_VALUE_LAST_MOD,
109 } notmuch_value_t;
110
111 /* Xapian (with flint backend) complains if we provide a term longer
112  * than this, but I haven't yet found a way to query the limit
113  * programmatically. */
114 #define NOTMUCH_TERM_MAX 245
115
116 #define NOTMUCH_METADATA_THREAD_ID_PREFIX "thread_id_"
117
118 /* For message IDs we have to be even more restrictive. Beyond fitting
119  * into the term limit, we also use message IDs to construct
120  * metadata-key values. And the documentation says that these should
121  * be restricted to about 200 characters. (The actual limit for the
122  * chert backend at least is 252.)
123  */
124 #define NOTMUCH_MESSAGE_ID_MAX (200 - sizeof (NOTMUCH_METADATA_THREAD_ID_PREFIX))
125
126 typedef enum _notmuch_private_status {
127     /* First, copy all the public status values. */
128     NOTMUCH_PRIVATE_STATUS_SUCCESS                      = NOTMUCH_STATUS_SUCCESS,
129     NOTMUCH_PRIVATE_STATUS_OUT_OF_MEMORY                = NOTMUCH_STATUS_OUT_OF_MEMORY,
130     NOTMUCH_PRIVATE_STATUS_READ_ONLY_DATABASE           = NOTMUCH_STATUS_READ_ONLY_DATABASE,
131     NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION             = NOTMUCH_STATUS_XAPIAN_EXCEPTION,
132     NOTMUCH_PRIVATE_STATUS_FILE_NOT_EMAIL               = NOTMUCH_STATUS_FILE_NOT_EMAIL,
133     NOTMUCH_PRIVATE_STATUS_NULL_POINTER                 = NOTMUCH_STATUS_NULL_POINTER,
134     NOTMUCH_PRIVATE_STATUS_TAG_TOO_LONG                 = NOTMUCH_STATUS_TAG_TOO_LONG,
135     NOTMUCH_PRIVATE_STATUS_UNBALANCED_FREEZE_THAW       = NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
136
137     /* Then add our own private values. */
138     NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG                = NOTMUCH_STATUS_LAST_STATUS,
139     NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND,
140     NOTMUCH_PRIVATE_STATUS_BAD_PREFIX,
141
142     NOTMUCH_PRIVATE_STATUS_LAST_STATUS
143 } notmuch_private_status_t;
144
145 /* Coerce a notmuch_private_status_t value to a notmuch_status_t
146  * value, generating an internal error if the private value is equal
147  * to or greater than NOTMUCH_STATUS_LAST_STATUS. (The idea here is
148  * that the caller has previously handled any expected
149  * notmuch_private_status_t values.)
150  *
151  * Note that the function _internal_error does not return. Evaluating
152  * to NOTMUCH_STATUS_SUCCESS is done purely to appease the compiler.
153  */
154 #define COERCE_STATUS(private_status, format, ...)                      \
155     ((private_status >= (notmuch_private_status_t) NOTMUCH_STATUS_LAST_STATUS) \
156      ?                                                                  \
157      _internal_error (format " (%s).\n",                                \
158                       ##__VA_ARGS__,                                    \
159                       __location__),                                    \
160      (notmuch_status_t) NOTMUCH_PRIVATE_STATUS_SUCCESS                  \
161      :                                                                  \
162      (notmuch_status_t) private_status)
163
164 /* Flags shared by various lookup functions. */
165 typedef enum _notmuch_find_flags {
166     /* Lookup without creating any documents.  This is the default
167      * behavior. */
168     NOTMUCH_FIND_LOOKUP = 0,
169     /* If set, create the necessary document (or documents) if they
170      * are missing.  Requires a read/write database. */
171     NOTMUCH_FIND_CREATE = 1 << 0,
172 } notmuch_find_flags_t;
173
174 typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
175
176 /* database.cc */
177
178 /* Lookup a prefix value by name.
179  *
180  * XXX: This should really be static inside of message.cc, and we can
181  * do that once we convert database.cc to use the
182  * _notmuch_message_add/remove_term functions. */
183 const char *
184 _find_prefix (const char *name);
185
186 /* Lookup a prefix value by name, including possibly user defined prefixes
187  */
188 const char *
189 _notmuch_database_prefix (notmuch_database_t *notmuch, const char *name);
190
191 char *
192 _notmuch_message_id_compressed (void *ctx, const char *message_id);
193
194 notmuch_status_t
195 _notmuch_database_ensure_writable (notmuch_database_t *notmuch);
196
197 notmuch_status_t
198 _notmuch_database_reopen (notmuch_database_t *notmuch);
199
200 void
201 _notmuch_database_log (notmuch_database_t *notmuch,
202                        const char *format, ...);
203
204 void
205 _notmuch_database_log_append (notmuch_database_t *notmuch,
206                               const char *format, ...);
207
208 unsigned long
209 _notmuch_database_new_revision (notmuch_database_t *notmuch);
210
211 const char *
212 _notmuch_database_relative_path (notmuch_database_t *notmuch,
213                                  const char *path);
214
215 notmuch_status_t
216 _notmuch_database_split_path (void *ctx,
217                               const char *path,
218                               const char **directory,
219                               const char **basename);
220
221 const char *
222 _notmuch_database_get_directory_db_path (const char *path);
223
224 unsigned int
225 _notmuch_database_generate_doc_id (notmuch_database_t *notmuch);
226
227 notmuch_private_status_t
228 _notmuch_database_find_unique_doc_id (notmuch_database_t *notmuch,
229                                       const char *prefix_name,
230                                       const char *value,
231                                       unsigned int *doc_id);
232
233 notmuch_status_t
234 _notmuch_database_find_directory_id (notmuch_database_t *database,
235                                      const char *path,
236                                      notmuch_find_flags_t flags,
237                                      unsigned int *directory_id);
238
239 const char *
240 _notmuch_database_get_directory_path (void *ctx,
241                                       notmuch_database_t *notmuch,
242                                       unsigned int doc_id);
243
244 notmuch_status_t
245 _notmuch_database_filename_to_direntry (void *ctx,
246                                         notmuch_database_t *notmuch,
247                                         const char *filename,
248                                         notmuch_find_flags_t flags,
249                                         char **direntry);
250
251 /* directory.cc */
252
253 notmuch_directory_t *
254 _notmuch_directory_create (notmuch_database_t *notmuch,
255                            const char *path,
256                            notmuch_find_flags_t flags,
257                            notmuch_status_t *status_ret);
258
259 unsigned int
260 _notmuch_directory_get_document_id (notmuch_directory_t *directory);
261
262 /* message.cc */
263
264 notmuch_message_t *
265 _notmuch_message_create (const void *talloc_owner,
266                          notmuch_database_t *notmuch,
267                          unsigned int doc_id,
268                          notmuch_private_status_t *status);
269
270 notmuch_message_t *
271 _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
272                                         const char *message_id,
273                                         notmuch_private_status_t *status);
274
275 unsigned int
276 _notmuch_message_get_doc_id (notmuch_message_t *message);
277
278 const char *
279 _notmuch_message_get_in_reply_to (notmuch_message_t *message);
280
281 notmuch_private_status_t
282 _notmuch_message_add_term (notmuch_message_t *message,
283                            const char *prefix_name,
284                            const char *value);
285
286 notmuch_private_status_t
287 _notmuch_message_remove_term (notmuch_message_t *message,
288                               const char *prefix_name,
289                               const char *value);
290
291 notmuch_private_status_t
292 _notmuch_message_has_term (notmuch_message_t *message,
293                            const char *prefix_name,
294                            const char *value,
295                            bool *result);
296
297 notmuch_private_status_t
298 _notmuch_message_gen_terms (notmuch_message_t *message,
299                             const char *prefix_name,
300                             const char *text);
301
302 void
303 _notmuch_message_upgrade_filename_storage (notmuch_message_t *message);
304
305 void
306 _notmuch_message_upgrade_folder (notmuch_message_t *message);
307
308 notmuch_status_t
309 _notmuch_message_add_filename (notmuch_message_t *message,
310                                const char *filename);
311
312 notmuch_status_t
313 _notmuch_message_remove_filename (notmuch_message_t *message,
314                                   const char *filename);
315
316 notmuch_status_t
317 _notmuch_message_rename (notmuch_message_t *message,
318                          const char *new_filename);
319
320 void
321 _notmuch_message_ensure_thread_id (notmuch_message_t *message);
322
323 void
324 _notmuch_message_set_header_values (notmuch_message_t *message,
325                                     const char *date,
326                                     const char *from,
327                                     const char *subject);
328
329 void
330 _notmuch_message_update_subject (notmuch_message_t *message,
331                                  const char *subject);
332
333 void
334 _notmuch_message_upgrade_last_mod (notmuch_message_t *message);
335
336 void
337 _notmuch_message_sync (notmuch_message_t *message);
338
339 notmuch_status_t
340 _notmuch_message_delete (notmuch_message_t *message);
341
342 notmuch_private_status_t
343 _notmuch_message_initialize_ghost (notmuch_message_t *message,
344                                    const char *thread_id);
345
346 void
347 _notmuch_message_close (notmuch_message_t *message);
348
349 /* Get a copy of the data in this message document.
350  *
351  * Caller should talloc_free the result when done.
352  *
353  * This function is intended to support database upgrade and really
354  * shouldn't be used otherwise. */
355 char *
356 _notmuch_message_talloc_copy_data (notmuch_message_t *message);
357
358 /* Clear the data in this message document.
359  *
360  * This function is intended to support database upgrade and really
361  * shouldn't be used otherwise. */
362 void
363 _notmuch_message_clear_data (notmuch_message_t *message);
364
365 /* Set the author member of 'message' - this is the representation used
366  * when displaying the message */
367 void
368 _notmuch_message_set_author (notmuch_message_t *message, const char *author);
369
370 /* Get the author member of 'message' */
371 const char *
372 _notmuch_message_get_author (notmuch_message_t *message);
373
374 /* message-file.c */
375
376 /* XXX: I haven't decided yet whether these will actually get exported
377  * into the public interface in notmuch.h
378  */
379
380 typedef struct _notmuch_message_file notmuch_message_file_t;
381
382 /* Open a file containing a single email message.
383  *
384  * The caller should call notmuch_message_close when done with this.
385  *
386  * Returns NULL if any error occurs.
387  */
388 notmuch_message_file_t *
389 _notmuch_message_file_open (notmuch_database_t *notmuch, const char *filename);
390
391 /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */
392 notmuch_message_file_t *
393 _notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
394                                 void *ctx, const char *filename);
395
396 /* Close a notmuch message previously opened with notmuch_message_open. */
397 void
398 _notmuch_message_file_close (notmuch_message_file_t *message);
399
400 /* Parse the message.
401  *
402  * This will be done automatically as necessary on other calls
403  * depending on it, but an explicit call allows for better error
404  * status reporting.
405  */
406 notmuch_status_t
407 _notmuch_message_file_parse (notmuch_message_file_t *message);
408
409 /* Get the gmime message of a message file.
410  *
411  * The message file is parsed as necessary.
412  *
413  * The GMimeMessage* is set to *mime_message on success (which the
414  * caller must not unref).
415  *
416  * XXX: Would be nice to not have to expose GMimeMessage here.
417  */
418 notmuch_status_t
419 _notmuch_message_file_get_mime_message (notmuch_message_file_t *message,
420                                         GMimeMessage **mime_message);
421
422 /* Get the value of the specified header from the message as a UTF-8 string.
423  *
424  * The message file is parsed as necessary.
425  *
426  * The header name is case insensitive.
427  *
428  * The Received: header is special - for it all Received: headers in
429  * the message are concatenated
430  *
431  * The returned value is owned by the notmuch message and is valid
432  * only until the message is closed. The caller should copy it if
433  * needing to modify the value or to hold onto it for longer.
434  *
435  * Returns NULL on errors, empty string if the message does not
436  * contain a header line matching 'header'.
437  */
438 const char *
439 _notmuch_message_file_get_header (notmuch_message_file_t *message,
440                                   const char *header);
441
442 notmuch_status_t
443 _notmuch_message_file_get_headers (notmuch_message_file_t *message_file,
444                                    const char **from_out,
445                                    const char **subject_out,
446                                    const char **to_out,
447                                    const char **date_out,
448                                    char **message_id_out);
449
450 const char *
451 _notmuch_message_file_get_filename (notmuch_message_file_t *message);
452
453 /* add-message.cc */
454 notmuch_status_t
455 _notmuch_database_link_message_to_parents (notmuch_database_t *notmuch,
456                                            notmuch_message_t *message,
457                                            notmuch_message_file_t *message_file,
458                                            const char **thread_id);
459 /* index.cc */
460
461 notmuch_status_t
462 _notmuch_message_index_file (notmuch_message_t *message,
463                              notmuch_indexopts_t *indexopts,
464                              notmuch_message_file_t *message_file);
465
466 /* messages.c */
467
468 typedef struct _notmuch_message_node {
469     notmuch_message_t *message;
470     struct _notmuch_message_node *next;
471 } notmuch_message_node_t;
472
473 typedef struct _notmuch_message_list {
474     notmuch_message_node_t *head;
475     notmuch_message_node_t **tail;
476 } notmuch_message_list_t;
477
478 /* There's a rumor that there's an alternate struct _notmuch_messages
479  * somewhere with some nasty C++ objects in it. We'll try to maintain
480  * ignorance of that here. (See notmuch_mset_messages_t in query.cc)
481  */
482 struct _notmuch_messages {
483     bool is_of_list_type;
484     notmuch_doc_id_set_t *excluded_doc_ids;
485     notmuch_message_node_t *iterator;
486 };
487
488 notmuch_message_list_t *
489 _notmuch_message_list_create (const void *ctx);
490
491 bool
492 _notmuch_message_list_empty (notmuch_message_list_t *list);
493
494 void
495 _notmuch_message_list_add_message (notmuch_message_list_t *list,
496                                    notmuch_message_t *message);
497
498 notmuch_messages_t *
499 _notmuch_messages_create (notmuch_message_list_t *list);
500
501 bool
502 _notmuch_messages_has_next (notmuch_messages_t *messages);
503
504 /* query.cc */
505
506 bool
507 _notmuch_mset_messages_valid (notmuch_messages_t *messages);
508
509 notmuch_message_t *
510 _notmuch_mset_messages_get (notmuch_messages_t *messages);
511
512 void
513 _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages);
514
515 bool
516 _notmuch_doc_id_set_contains (notmuch_doc_id_set_t *doc_ids,
517                               unsigned int doc_id);
518
519 void
520 _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,
521                             unsigned int doc_id);
522
523 /* querying xapian documents by type (e.g. "mail" or "ghost"): */
524 notmuch_status_t
525 _notmuch_query_search_documents (notmuch_query_t *query,
526                                  const char *type,
527                                  notmuch_messages_t **out);
528
529 notmuch_status_t
530 _notmuch_query_count_documents (notmuch_query_t *query,
531                                 const char *type,
532                                 unsigned *count_out);
533 /* message-id.c */
534
535 /* Parse an RFC 822 message-id, discarding whitespace, any RFC 822
536  * comments, and the '<' and '>' delimiters.
537  *
538  * If not NULL, then *next will be made to point to the first character
539  * not parsed, (possibly pointing to the final '\0' terminator.
540  *
541  * Returns a newly talloc'ed string belonging to 'ctx'.
542  *
543  * Returns NULL if there is any error parsing the message-id. */
544 char *
545 _notmuch_message_id_parse (void *ctx, const char *message_id, const char **next);
546
547 /* Parse a message-id, discarding leading and trailing whitespace, and
548  * '<' and '>' delimiters.
549  *
550  * Apply a probably-stricter-than RFC definition of what is allowed in
551  * a message-id. In particular, forbid whitespace.
552  *
553  * Returns a newly talloc'ed string belonging to 'ctx'.
554  *
555  * Returns NULL if there is any error parsing the message-id.
556  */
557
558 char *
559 _notmuch_message_id_parse_strict (void *ctx, const char *message_id);
560
561
562 /* message.cc */
563
564 void
565 _notmuch_message_add_reply (notmuch_message_t *message,
566                             notmuch_message_t *reply);
567
568 void
569 _notmuch_message_remove_unprefixed_terms (notmuch_message_t *message);
570
571 const char *
572 _notmuch_message_get_thread_id_only (notmuch_message_t *message);
573
574 size_t _notmuch_message_get_thread_depth (notmuch_message_t *message);
575
576 void
577 _notmuch_message_label_depths (notmuch_message_t *message,
578                                size_t depth);
579
580 notmuch_message_list_t *
581 _notmuch_message_sort_subtrees (void *ctx, notmuch_message_list_t *list);
582
583 /* sha1.c */
584
585 char *
586 _notmuch_sha1_of_string (const char *str);
587
588 char *
589 _notmuch_sha1_of_file (const char *filename);
590
591 /* string-list.c */
592
593 typedef struct _notmuch_string_node {
594     char *string;
595     struct _notmuch_string_node *next;
596 } notmuch_string_node_t;
597
598 typedef struct _notmuch_string_list {
599     int length;
600     notmuch_string_node_t *head;
601     notmuch_string_node_t **tail;
602 } notmuch_string_list_t;
603
604 notmuch_string_list_t *
605 _notmuch_string_list_create (const void *ctx);
606
607 /*
608  * return the number of strings in 'list'
609  */
610 int
611 _notmuch_string_list_length (notmuch_string_list_t *list);
612
613 /* Add 'string' to 'list'.
614  *
615  * The list will create its own talloced copy of 'string'.
616  */
617 void
618 _notmuch_string_list_append (notmuch_string_list_t *list,
619                              const char *string);
620
621 void
622 _notmuch_string_list_sort (notmuch_string_list_t *list);
623
624 const notmuch_string_list_t *
625 _notmuch_message_get_references (notmuch_message_t *message);
626
627 /* string-map.c */
628 typedef struct _notmuch_string_map notmuch_string_map_t;
629 typedef struct _notmuch_string_map_iterator notmuch_string_map_iterator_t;
630 notmuch_string_map_t *
631 _notmuch_string_map_create (const void *ctx);
632
633 void
634 _notmuch_string_map_append (notmuch_string_map_t *map,
635                             const char *key,
636                             const char *value);
637
638 const char *
639 _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);
640
641 notmuch_string_map_iterator_t *
642 _notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,
643                                      bool exact);
644
645 bool
646 _notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iter);
647
648 void
649 _notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iter);
650
651 const char *
652 _notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator);
653
654 const char *
655 _notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);
656
657 void
658 _notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);
659
660 /* Create an iterator for user headers. Destroy with
661  * _notmuch_string_map_iterator_destroy. Actually in database.cc*/
662 notmuch_string_map_iterator_t *
663 _notmuch_database_user_headers (notmuch_database_t *notmuch);
664
665 /* tags.c */
666
667 notmuch_tags_t *
668 _notmuch_tags_create (const void *ctx, notmuch_string_list_t *list);
669
670 /* filenames.c */
671
672 /* The notmuch_filenames_t iterates over a notmuch_string_list_t of
673  * file names */
674 notmuch_filenames_t *
675 _notmuch_filenames_create (const void *ctx,
676                            notmuch_string_list_t *list);
677
678 /* thread.cc */
679
680 notmuch_thread_t *
681 _notmuch_thread_create (void *ctx,
682                         notmuch_database_t *notmuch,
683                         unsigned int seed_doc_id,
684                         notmuch_doc_id_set_t *match_set,
685                         notmuch_string_list_t *excluded_terms,
686                         notmuch_exclude_t omit_exclude,
687                         notmuch_sort_t sort);
688
689 /* indexopts.c */
690
691 struct _notmuch_indexopts {
692     _notmuch_crypto_t crypto;
693 };
694
695 #define CONFIG_HEADER_PREFIX "index.header."
696
697 #define EMPTY_STRING(s) ((s)[0] == '\0')
698
699 NOTMUCH_END_DECLS
700
701 #ifdef __cplusplus
702 /* Implicit typecast from 'void *' to 'T *' is okay in C, but not in
703  * C++. In talloc_steal, an explicit cast is provided for type safety
704  * in some GCC versions. Otherwise, a cast is required. Provide a
705  * template function for this to maintain type safety, and redefine
706  * talloc_steal to use it.
707  */
708 #if ! (__GNUC__ >= 3)
709 template <class T> T *
710 _notmuch_talloc_steal (const void *new_ctx, const T *ptr)
711 {
712     return static_cast<T *> (talloc_steal (new_ctx, ptr));
713 }
714 #undef talloc_steal
715 #define talloc_steal _notmuch_talloc_steal
716 #endif
717 #endif
718
719 #endif