build: put manpages in right place
[rb-79.git] / rb79.h
blob033ffb636f52ad791578155150b4f15a2fa7d064
1 /*
2 * Copyright (c) 2017, 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 *trip_salt;
214 size_t trip_salt_len;
215 const struct board *boards;
216 size_t boards_num;
217 size_t max_form_data_size;
218 size_t max_file_size;
219 size_t max_text_len;
220 const struct filetype *filetypes;
221 size_t filetypes_num;
222 const char *file_description_prog;
223 const char **headers;
224 size_t headers_num;
225 const struct challenge *challenges;
226 size_t challenges_num;
227 const struct wordfilter_input *wordfilter_inputs;
228 size_t wordfilter_inputs_num;
231 /* db_writeback_ZZZ takes a callback. */
232 typedef int (*post_writeback)(struct prepared_post *p, FILE *f, uint_fast8_t
233 is_op, uint_fast8_t is_summary, const
234 char *board_name, uintmax_t
235 total_posts_in_thread, uint_fast8_t hr_before);
237 /* db-ZZZ.c (currently only sqlite3, but it used to be MySQL) */
239 setup_dbs(const struct configuration *conf);
242 db_construct_post_link(const char *board, size_t board_len, const char *post,
243 size_t post_len, int *found, char **out,
244 size_t *out_len);
247 db_cull_threads(size_t board_idx, size_t *out_num_pages);
250 db_check_bans(const char *ip, size_t board_idx, time_t now, int *out_is_banned,
251 char **out_ban_until, char **out_ban_reason);
254 db_check_cooldowns(const char *ip, size_t board_idx, time_t now,
255 int *out_is_cooled, char **out_cooldown_length);
258 db_cull_and_report_threads(size_t board_idx, uintmax_t **out_thread_ids,
259 size_t *out_thread_id_num, size_t *out_num_pages);
262 db_extract_subject(size_t board_idx, uintmax_t thread, char **out_subject,
263 size_t *out_subject_len);
266 db_insert_ban(uint_fast8_t global_ban, size_t board_idx, const char *first_ip,
267 const char *last_ip, const char *message, time_t ban_start, time_t
268 ban_expiry);
271 db_insert_post(const char *ip, size_t in_thread, int cooldown, struct
272 post_cmd *pc, int *thread_dne, int *thread_closed,
273 int *thread_full,
274 uintmax_t *post_id);
277 db_is_op(size_t board_idx, uintmax_t post_id, uint_fast8_t *out_is_op);
280 db_moderate_post(size_t board_idx, uintmax_t post_id, const
281 char *moderator_comment, uint_fast8_t change_sticky,
282 uint_fast8_t sticky_status,
283 uint_fast8_t change_close, uint_fast8_t close_status);
286 db_remove_thread_and_files(size_t board_idx, uintmax_t thread_id);
289 db_remove_post_and_files(size_t board_idx, uintmax_t thread_id);
292 db_update_file_info(size_t board_idx, uintmax_t post_id, const char *info,
293 size_t info_len, const char *system_full_path, size_t
294 system_full_path_len,
295 const char *system_thumb_path, size_t
296 system_thumb_path_len);
299 db_writeback_posts_in_thread(size_t board_idx, uintmax_t thread, FILE *f,
300 post_writeback pw_function);
303 db_writeback_thread_summaries(size_t board_idx, uintmax_t *thread_ids, size_t
304 thread_ids_num, FILE *f);
307 clean_dbs(void);
309 /* locks.c */
311 setup_locks(const struct configuration *conf);
314 lock_acquire(size_t board_idx);
317 lock_release(size_t board_idx);
320 clean_locks(void);
322 /* multipart.c */
324 setup_multipart(void);
327 multipart_decompose(const char *full_data, size_t full_data_len, struct
328 post_cmd *post_cmd);
331 clean_multipart(void);
333 /* preconditions.c */
335 preconditions_check(const struct configuration *conf);
337 /* sanitize-comment.c */
339 setup_sanitize_comment(const struct configuration *conf);
342 st_sanitize_text(struct post_cmd *pc, int *our_fault);
345 clean_sanitize_comment(void);
347 /* sanitize-file.c */
349 setup_sanitize_file(const struct configuration *conf);
352 sf_check_mime_type(const char *buf, size_t len, const struct
353 filetype **out_filetype);
356 sf_describe_file(const char *mimetype, const char *filepath,
357 char **out_description, size_t *out_len);
360 sf_install_files(size_t board_idx, const char *buf, size_t len, time_t *now,
361 const struct filetype *filetype, char **out_abs_path,
362 char **out_path,
363 size_t *out_path_len, char **out_thumb_path,
364 size_t *out_thumb_path_len,
365 int *our_fault);
368 clean_sanitize_file(void);
370 /* tripcodes.c */
372 setup_tripcodes(const struct configuration *conf);
375 tripcodes_calculate(struct post_cmd *p);
378 clean_tripcodes(void);
380 /* util.c */
381 char *
382 util_iso8601_from_time_t(time_t t);
385 util_normalize_ip(const char *in, char **out);
388 util_rebuild(struct configuration *conf);
390 /* write-thread.c */
392 setup_write_thread(const struct configuration *conf);
395 wt_remove_files(const char *system_full_path, size_t system_full_path_len, const
396 char *system_thumb_path, size_t system_thumb_path_len);
399 wt_remove_thread_page(size_t board_idx, uintmax_t thread_id);
402 wt_write_board(size_t board_idx, uintmax_t *thread_ids, size_t thread_ids_num,
403 size_t board_pages_num);
406 wt_write_post(struct prepared_post *p, FILE *f, uint_fast8_t is_op, uint_fast8_t
407 is_summary, const char *board_name, uintmax_t
408 total_posts_in_thread,
409 uint_fast8_t hr_before);
412 wt_write_thread(size_t board_idx, uintmax_t thread);
414 void
415 clean_write_thread(void);