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
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] */
21 /* Short name, like "a" or "b" */
24 /* Like "Anime" or "Random" */
27 /* Cooldown after you post text */
30 /* Cooldown after you post textless */
33 /* How many threads are on each page */
34 unsigned int threads_per_page
;
36 /* How many pages total */
37 unsigned int num_pages
;
39 /* Whether posts here show up in /recent */
40 unsigned int appears_in_recent
;
43 /* Things users can try to do */
44 enum action_t
{ NONE
, REPLY
, NEWTHREAD
, REBUILD
};
47 * A post as it will be stored in (or retrieved from) the database.
48 * As part of post_cmd, this will be built up by rb79.c, inserted
49 * into the db by db_insert_post, and retrieved for writing to
50 * filesystem in write-thread.c
52 struct prepared_post
{
53 /* When it was issued */
57 * This requires db access to retrieve, so it may be 0 for
58 * most of the object's life
62 /* Flags, in case this is the OP of a thread */
63 uint_fast8_t thread_closed
;
64 uint_fast8_t thread_stickied
;
66 /* HTML-esc'd, ready for inserting into pages */
78 /* Comes from a struct filetype. A copy, needs to be freed */
82 /* The name the uploader called the file (HTML-esc'd) */
86 /* The path for the full file, like /m/src/123.jpg */
87 char *system_full_path
;
88 size_t system_full_path_len
;
90 /* The path for the thumbnail, like /m/src/123s.jpg */
91 char *system_thumb_path
;
92 size_t system_thumb_path_len
;
94 /* A string like "image/jpeg, 30KiB, 500x399" */
98 /* The main server ignores this, but mod tools use it */
104 * Strings are filled in by multipart.c, where we are quite
105 * thankful that everything is guaranteed to be UTF-8.
106 * Parsing, if needed, is done by rb79.c
133 /* tripcode - calculated from email */
147 size_t file_name_len
;
149 size_t file_contents_len
;
153 size_t challenge_id_len
;
155 /* challengeresponse= */
156 char *challenge_response
;
157 size_t challenge_response_len
;
161 * Everything below is filled in by rb79.c as derived data
163 enum action_t action_id
;
167 /* This is what goes into the database. */
168 struct prepared_post prepared
;
171 * The following is intermediate data for sanitizing input
172 * comments. XXX: figure out if these can be safely removed
173 * from this object, because they're sort of messy.
176 /* A sort of normalized UTF-8 comment */
177 char *scannable_comment
;
178 size_t scannable_comment_len
;
180 /* see to_scannable() for this one */
181 size_t *position_map
;
182 size_t position_map_len
;
185 /* Filetype/thumbnailing options */
188 const char *mime_type
;
190 const char *install_command
;
191 const char *thumb_creation_command
;
192 const char *static_thumbnail
;
195 #define NUM_CHALLENGE_ANSWERS 5
197 /* wakarimasen-style CAPTCHA */
200 const char *question
;
201 const char *answers
[NUM_CHALLENGE_ANSWERS
];
204 /* regex-backed wordfilter */
205 struct wordfilter_input
{
208 const char *replacement
;
211 /* regex-backed forbidden input */
212 struct forbidden_input
{
217 /* See config.def.h for detailed descriptions. */
218 struct configuration
{
220 const char *static_www_folder
;
221 const char *work_path
;
222 const char *temp_dir_template
;
223 const char *trip_salt
;
224 size_t trip_salt_len
;
225 const struct board
*boards
;
227 size_t max_form_data_size
;
228 size_t max_file_size
;
230 const struct filetype
*filetypes
;
231 size_t filetypes_num
;
232 const char *file_description_prog
;
233 const char **headers
;
235 const struct challenge
*challenges
;
236 size_t challenges_num
;
237 const struct wordfilter_input
*wordfilter_inputs
;
238 size_t wordfilter_inputs_num
;
239 const struct forbidden_input
*forbidden_inputs
;
240 size_t forbidden_inputs_num
;
243 /* db_writeback_ZZZ takes a callback. */
244 typedef int (*post_writeback
)(struct prepared_post
*p
, FILE *f
, uint_fast8_t
245 is_op
, uint_fast8_t is_summary
, uint_fast8_t
246 is_recent
, const char *board_name
,
247 uintmax_t in_thread
, uintmax_t
248 total_posts_in_thread
, uint_fast8_t hr_before
);
250 /* db-ZZZ.c (currently only sqlite3, but it used to be MySQL) */
252 setup_dbs(const struct configuration
*conf
);
255 db_construct_post_link(const char *board
, size_t board_len
, const char *post
,
256 size_t post_len
, int *found
, char **out
,
260 db_cull_threads(size_t board_idx
, size_t *out_num_pages
);
263 db_check_bans(const char *ip
, size_t board_idx
, time_t now
, int *out_is_banned
,
264 char **out_ban_until
, char **out_ban_reason
);
267 db_check_cooldowns(const char *ip
, size_t board_idx
, time_t now
,
268 int *out_is_cooled
, char **out_cooldown_length
);
271 db_cull_and_report_threads(size_t board_idx
, uintmax_t **out_thread_ids
,
272 size_t *out_thread_id_num
, size_t *out_num_pages
);
275 db_extract_subject(size_t board_idx
, uintmax_t thread
, char **out_subject
,
276 size_t *out_subject_len
);
279 db_insert_ban(uint_fast8_t global_ban
, size_t board_idx
, const char *first_ip
,
280 const char *last_ip
, const char *message
, time_t ban_start
, time_t
284 db_insert_post(const char *ip
, size_t in_thread
, int cooldown
, struct
285 post_cmd
*pc
, int *thread_dne
, int *thread_closed
,
290 db_is_op(size_t board_idx
, uintmax_t post_id
, uint_fast8_t *out_is_op
);
293 db_moderate_post(size_t board_idx
, uintmax_t post_id
, const
294 char *moderator_comment
, uint_fast8_t change_sticky
,
295 uint_fast8_t sticky_status
,
296 uint_fast8_t change_close
, uint_fast8_t close_status
);
299 db_remove_thread_and_files(size_t board_idx
, uintmax_t thread_id
);
302 db_remove_post_and_files(size_t board_idx
, uintmax_t thread_id
);
305 db_update_file_info(size_t board_idx
, uintmax_t post_id
, const char *info
,
306 size_t info_len
, const char *system_full_path
, size_t
307 system_full_path_len
,
308 const char *system_thumb_path
, size_t
309 system_thumb_path_len
);
312 db_writeback_posts_in_thread(size_t board_idx
, uintmax_t thread
, FILE *f
,
313 post_writeback pw_function
);
316 db_writeback_recent_posts(FILE *f
, post_writeback pw_function
);
319 db_writeback_thread_summaries(size_t board_idx
, uintmax_t *thread_ids
, size_t
320 thread_ids_num
, FILE *f
);
327 setup_locks(const struct configuration
*conf
);
330 lock_acquire(size_t board_idx
);
333 lock_acquire_recent(void);
336 lock_release(size_t board_idx
);
339 lock_release_recent(void);
346 setup_multipart(void);
349 multipart_decompose(const char *full_data
, size_t full_data_len
, struct
353 clean_multipart(void);
355 /* preconditions.c */
357 preconditions_check(const struct configuration
*conf
);
359 /* sanitize-comment.c */
361 setup_sanitize_comment(const struct configuration
*conf
);
364 st_sanitize_text(struct post_cmd
*pc
, int *our_fault
);
367 clean_sanitize_comment(void);
369 /* sanitize-file.c */
371 setup_sanitize_file(const struct configuration
*conf
);
374 sf_check_mime_type(const char *buf
, size_t len
, const struct
375 filetype
**out_filetype
);
378 sf_describe_file(const char *mimetype
, const char *filepath
,
379 char **out_description
, size_t *out_len
);
382 sf_install_files(size_t board_idx
, const char *buf
, size_t len
, time_t *now
,
383 const struct filetype
*filetype
, char **out_abs_path
,
385 size_t *out_path_len
, char **out_thumb_path
,
386 size_t *out_thumb_path_len
,
390 clean_sanitize_file(void);
394 setup_tripcodes(const struct configuration
*conf
);
397 tripcodes_calculate(struct post_cmd
*p
);
400 clean_tripcodes(void);
404 util_iso8601_from_time_t(time_t t
);
407 util_normalize_ip(const char *in
, char **out
);
410 util_rebuild(struct configuration
*conf
);
414 setup_write_thread(const struct configuration
*conf
);
417 wt_remove_files(const char *system_full_path
, size_t system_full_path_len
, const
418 char *system_thumb_path
, size_t system_thumb_path_len
);
421 wt_remove_thread_page(size_t board_idx
, uintmax_t thread_id
);
424 wt_write_board(size_t board_idx
, uintmax_t *thread_ids
, size_t thread_ids_num
,
425 size_t board_pages_num
);
428 wt_write_post(struct prepared_post
*p
, FILE *f
, uint_fast8_t is_op
, uint_fast8_t
429 is_summary
, uint_fast8_t is_recent
, const char *board_name
,
431 uintmax_t total_posts_in_thread
, uint_fast8_t hr_before
);
434 wt_write_recent_page(void);
437 wt_write_thread(size_t board_idx
, uintmax_t thread
);
440 clean_write_thread(void);