Fix tg_termpos1 for 64-bit termpos
[xapian.git] / xapian-applications / omega / handler.h
blob2f07224a0dd34d409ae49ea087ceb24da6ec2b32
1 /** @file
2 * @brief Extract text and metadata using an external library.
3 */
4 /* Copyright (C) 2011,2022,2023 Olly Betts
5 * Copyright (C) 2019 Bruno Baruffaldi
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
23 #ifndef OMEGA_INCLUDED_HANDLER_H
24 #define OMEGA_INCLUDED_HANDLER_H
26 #include <cstring>
27 #include <string>
29 /** Called exactly once during helper start-up.
31 * This will be called before any calls to extract().
33 * Should return true if initialisation succeeds, false (or throw a C++
34 * exception) if it fails.
36 bool
37 initialise();
39 /** Extract information from the @a filename and store it in the
40 * corresponding variable.
42 * @param filename Path to the file.
43 * @param mimetype Mimetype of the file.
45 * Note: This function should only be used by an assistant process.
47 * See Worker::extract() for more details.
49 void
50 extract(const std::string& filename,
51 const std::string& mimetype);
53 enum Field {
54 FIELD_BODY,
55 FIELD_TITLE,
56 FIELD_KEYWORDS,
57 FIELD_AUTHOR,
58 FIELD_PAGE_COUNT,
59 FIELD_CREATED_DATE,
60 FIELD_ATTACHMENT,
61 FIELD_TO,
62 FIELD_CC,
63 FIELD_BCC,
64 FIELD_MESSAGE_ID,
65 FIELD_ERROR,
66 FIELD_END
69 /** Respond with extracted data.
71 * @param field FIELD_* code
72 * @param data pointer to field content
73 * @param len length of field content in bytes
75 void
76 send_field(Field field, const char* data, size_t len);
78 /** Respond with extracted data.
80 * @param field FIELD_* code
81 * @param data pointer to nul-terminated field content
83 inline void
84 send_field(Field field, const char* data) {
85 if (data) send_field(field, data, std::strlen(data));
88 /** Respond with extracted data.
90 * @param field FIELD_* code
91 * @param data field content as std::string
93 inline void
94 send_field(Field field, const std::string& s) {
95 send_field(field, s.data(), s.size());
98 void send_field_page_count(int value);
100 void send_field_created_date(time_t value);
102 #endif // OMEGA_INCLUDED_HANDLER_H