config: make conv dir configurable
[rb-79.git] / rb79.h
blob5fb4aa617d36f980788b2bf97ecaded3704396b3
1 /*
2 * Copyright (c) 2017-2018, De Rais <derais@cock.li>
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Defines what's needed to identifiy a board['s folder] */
20 struct board {
21 /* Short name, like "a" or "b" */
22 const char *name;
24 /* Like "Anime" or "Random" */
25 const char *title;
27 /* Cooldown after you post text */
28 int text_cooldown;
30 /* Cooldown after you post textless */
31 int blank_cooldown;
33 /* How many threads are on each page */
34 unsigned int threads_per_page;
36 /* How many pages total */
37 unsigned int num_pages;
40 /* Things users can try to do */
41 enum action_t { NONE, REPLY, NEWTHREAD, REBUILD };
44 * A post as it will be stored in (or retrieved from) the database.
45 * As part of post_cmd, this will be built up by rb79.c, inserted
46 * into the db by db_insert_post, and retrieved for writing to
47 * filesystem in write-thread.c
49 struct prepared_post {
50 /* When it was issued */
51 time_t now;
54 * This requires db access to retrieve, so it may be 0 for
55 * most of the object's life
57 uintmax_t id;
59 /* Flags, in case this is the OP of a thread */
60 uint_fast8_t thread_closed;
61 uint_fast8_t thread_stickied;
63 /* HTML-esc'd, ready for inserting into pages */
64 char *name;
65 size_t name_len;
66 char *email;
67 size_t email_len;
68 char *tripcode;
69 size_t tripcode_len;
70 char *subject;
71 size_t subject_len;
72 char *comment;
73 size_t comment_len;
75 /* Comes from a struct filetype. A copy, needs to be freed */
76 char *ext;
77 size_t ext_len;
79 /* The name the uploader called the file (HTML-esc'd) */
80 char *file_name;
81 size_t file_name_len;
83 /* The path for the full file, like /m/src/123.jpg */
84 char *system_full_path;
85 size_t system_full_path_len;
87 /* The path for the thumbnail, like /m/src/123s.jpg */
88 char *system_thumb_path;
89 size_t system_thumb_path_len;
91 /* A string like "image/jpeg, 30KiB, 500x399" */
92 char *file_info;
93 size_t file_info_len;
95 /* The main server ignores this, but mod tools use it */
96 char *ip;
97 size_t ip_len;
99 struct post_cmd {
101 * Strings are filled in by multipart.c, where we are quite
102 * thankful that everything is guaranteed to be UTF-8.
103 * Parsing, if needed, is done by rb79.c
105 struct {
106 /* action= */
107 char *action;
108 size_t action_len;
110 /* board= */
111 char *board;
112 size_t board_len;
114 /* thread= */
115 char *thread;
116 size_t thread_len;
118 /* post= */
119 char *post;
120 size_t post_len;
122 /* name= */
123 char *name;
124 size_t name_len;
126 /* email= */
127 char *email;
128 size_t email_len;
130 /* tripcode - calculated from email */
131 char *tripcode;
132 size_t tripcode_len;
134 /* subject= */
135 char *subject;
136 size_t subject_len;
138 /* comment= */
139 char *comment;
140 size_t comment_len;
142 /* file upload */
143 char *file_name;
144 size_t file_name_len;
145 char *file_contents;
146 size_t file_contents_len;
148 /* challengeid= */
149 char *challenge_id;
150 size_t challenge_id_len;
152 /* challengeresponse= */
153 char *challenge_response;
154 size_t challenge_response_len;
155 } raw;
158 * Everything below is filled in by rb79.c as derived data
160 enum action_t action_id;
161 uintmax_t board_idx;
162 uintmax_t thread_id;
164 /* This is what goes into the database. */
165 struct prepared_post prepared;
168 * The following is intermediate data for sanitizing input
169 * comments. XXX: figure out if these can be safely removed
170 * from this object, because they're sort of messy.
173 /* A sort of normalized UTF-8 comment */
174 char *scannable_comment;
175 size_t scannable_comment_len;
177 /* see to_scannable() for this one */
178 size_t *position_map;
179 size_t position_map_len;
182 /* Filetype/thumbnailing options */
183 struct filetype {
184 /* */
185 const char *mime_type;
186 const char *ext;
187 const char *install_command;
188 const char *thumb_creation_command;
189 const char *static_thumbnail;
192 #define NUM_CHALLENGE_ANSWERS 5
194 /* wakarimasen-style CAPTCHA */
195 struct challenge {
196 /* */
197 const char *question;
198 const char *answers[NUM_CHALLENGE_ANSWERS];
201 /* regex-backed wordfilter */
202 struct wordfilter_input {
203 /* */
204 const char *pattern;
205 const char *replacement;
208 /* See config.def.h for detailed descriptions. */
209 struct configuration {
210 /* */
211 const char *static_www_folder;
212 const char *work_path;
213 const char *temp_dir_template;
214 const char *trip_salt;
215 size_t trip_salt_len;
216 const struct board *boards;
217 size_t boards_num;
218 size_t max_form_data_size;
219 size_t max_file_size;
220 size_t max_text_len;
221 const struct filetype *filetypes;
222 size_t filetypes_num;
223 const char *file_description_prog;
224 const char **headers;
225 size_t headers_num;
226 const struct challenge *challenges;
227 size_t challenges_num;
228 const struct wordfilter_input *wordfilter_inputs;
229 size_t wordfilter_inputs_num;
232 /* db_writeback_ZZZ takes a callback. */
233 typedef int (*post_writeback)(struct prepared_post *p, FILE *f, uint_fast8_t
234 is_op, uint_fast8_t is_summary, uint_fast8_t
235 is_recent, const char *board_name,
236 uintmax_t in_thread, uintmax_t
237 total_posts_in_thread, uint_fast8_t hr_before);
239 /* db-ZZZ.c (currently only sqlite3, but it used to be MySQL) */
241 setup_dbs(const struct configuration *conf);
244 db_construct_post_link(const char *board, size_t board_len, const char *post,
245 size_t post_len, int *found, char **out,
246 size_t *out_len);
249 db_cull_threads(size_t board_idx, size_t *out_num_pages);
252 db_check_bans(const char *ip, size_t board_idx, time_t now, int *out_is_banned,
253 char **out_ban_until, char **out_ban_reason);
256 db_check_cooldowns(const char *ip, size_t board_idx, time_t now,
257 int *out_is_cooled, char **out_cooldown_length);
260 db_cull_and_report_threads(size_t board_idx, uintmax_t **out_thread_ids,
261 size_t *out_thread_id_num, size_t *out_num_pages);
264 db_extract_subject(size_t board_idx, uintmax_t thread, char **out_subject,
265 size_t *out_subject_len);
268 db_insert_ban(uint_fast8_t global_ban, size_t board_idx, const char *first_ip,
269 const char *last_ip, const char *message, time_t ban_start, time_t
270 ban_expiry);
273 db_insert_post(const char *ip, size_t in_thread, int cooldown, struct
274 post_cmd *pc, int *thread_dne, int *thread_closed,
275 int *thread_full,
276 uintmax_t *post_id);
279 db_is_op(size_t board_idx, uintmax_t post_id, uint_fast8_t *out_is_op);
282 db_moderate_post(size_t board_idx, uintmax_t post_id, const
283 char *moderator_comment, uint_fast8_t change_sticky,
284 uint_fast8_t sticky_status,
285 uint_fast8_t change_close, uint_fast8_t close_status);
288 db_remove_thread_and_files(size_t board_idx, uintmax_t thread_id);
291 db_remove_post_and_files(size_t board_idx, uintmax_t thread_id);
294 db_update_file_info(size_t board_idx, uintmax_t post_id, const char *info,
295 size_t info_len, const char *system_full_path, size_t
296 system_full_path_len,
297 const char *system_thumb_path, size_t
298 system_thumb_path_len);
301 db_writeback_posts_in_thread(size_t board_idx, uintmax_t thread, FILE *f,
302 post_writeback pw_function);
305 db_writeback_recent_posts(FILE *f, post_writeback pw_function);
308 db_writeback_thread_summaries(size_t board_idx, uintmax_t *thread_ids, size_t
309 thread_ids_num, FILE *f);
312 clean_dbs(void);
314 /* locks.c */
316 setup_locks(const struct configuration *conf);
319 lock_acquire(size_t board_idx);
322 lock_acquire_recent(void);
325 lock_release(size_t board_idx);
328 lock_release_recent(void);
331 clean_locks(void);
333 /* multipart.c */
335 setup_multipart(void);
338 multipart_decompose(const char *full_data, size_t full_data_len, struct
339 post_cmd *post_cmd);
342 clean_multipart(void);
344 /* preconditions.c */
346 preconditions_check(const struct configuration *conf);
348 /* sanitize-comment.c */
350 setup_sanitize_comment(const struct configuration *conf);
353 st_sanitize_text(struct post_cmd *pc, int *our_fault);
356 clean_sanitize_comment(void);
358 /* sanitize-file.c */
360 setup_sanitize_file(const struct configuration *conf);
363 sf_check_mime_type(const char *buf, size_t len, const struct
364 filetype **out_filetype);
367 sf_describe_file(const char *mimetype, const char *filepath,
368 char **out_description, size_t *out_len);
371 sf_install_files(size_t board_idx, const char *buf, size_t len, time_t *now,
372 const struct filetype *filetype, char **out_abs_path,
373 char **out_path,
374 size_t *out_path_len, char **out_thumb_path,
375 size_t *out_thumb_path_len,
376 int *our_fault);
379 clean_sanitize_file(void);
381 /* tripcodes.c */
383 setup_tripcodes(const struct configuration *conf);
386 tripcodes_calculate(struct post_cmd *p);
389 clean_tripcodes(void);
391 /* util.c */
392 char *
393 util_iso8601_from_time_t(time_t t);
396 util_normalize_ip(const char *in, char **out);
399 util_rebuild(struct configuration *conf);
401 /* write-thread.c */
403 setup_write_thread(const struct configuration *conf);
406 wt_remove_files(const char *system_full_path, size_t system_full_path_len, const
407 char *system_thumb_path, size_t system_thumb_path_len);
410 wt_remove_thread_page(size_t board_idx, uintmax_t thread_id);
413 wt_write_board(size_t board_idx, uintmax_t *thread_ids, size_t thread_ids_num,
414 size_t board_pages_num);
417 wt_write_post(struct prepared_post *p, FILE *f, uint_fast8_t is_op, uint_fast8_t
418 is_summary, uint_fast8_t is_recent, const char *board_name,
419 uintmax_t in_thread,
420 uintmax_t total_posts_in_thread, uint_fast8_t hr_before);
423 wt_write_recent_page(void);
426 wt_write_thread(size_t board_idx, uintmax_t thread);
428 void
429 clean_write_thread(void);