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
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.
32 const char *program_name
= "rb79-delete-post";
34 /* Show usage message, do not exit */
37 size_t len
= strlen(program_name
);
39 printf("Usage: %s -b board-name\n", program_name
);
40 printf(" %*s -p post-id\n", (int) len
, "");
44 int main(int argc
, char **argv
)
47 struct configuration conf
= { 0 };
49 const char *b_arg
= 0;
51 const char *p_arg
= 0;
52 uintmax_t post_id
= 0;
53 uint_fast8_t actually_is_op
= 0;
55 setlocale(LC_ALL
, "");
58 while ((opt
= getopt(argc
, argv
, "b:p:")) != -1) {
63 ERROR_MESSAGE("-b already specified");
72 ERROR_MESSAGE("-p already specified");
90 conf
= (struct configuration
) {
92 .static_www_folder
= static_www_folder
, /* */
93 .work_path
= work_path
, /* */
94 .trip_salt
= trip_salt
, /* */
95 .trip_salt_len
= strlen(trip_salt
), /* */
96 .boards
= boards
, /* */
97 .boards_num
= NUM_OF(boards
), /* */
98 .max_form_data_size
= max_form_data_size
, /* */
99 .max_file_size
= max_file_size
, /* */
100 .max_text_len
= max_text_len
, /* */
101 .filetypes
= filetypes
, /* */
102 .filetypes_num
= NUM_OF(filetypes
), /* */
103 .file_description_prog
= file_description_prog
, /* */
104 .headers
= headers
, /* */
105 .headers_num
= NUM_OF(headers
), /* */
106 .challenges
= challenges
, /* */
107 .challenges_num
= NUM_OF(challenges
), /* */
108 .wordfilter_inputs
= wordfilter_inputs
, /* */
109 .wordfilter_inputs_num
= NUM_OF(wordfilter_inputs
), /* */
112 /* Interpret board */
113 board_idx
= (size_t) -1;
115 for (size_t j
= 0; j
< conf
.boards_num
; ++j
) {
116 if (!strcmp(conf
.boards
[j
].name
, b_arg
)) {
121 if (board_idx
== (size_t) -1) {
122 ERROR_MESSAGE("No board \"%s\" known", b_arg
);
128 post_id
= strtoull(p_arg
, 0, 0);
132 PERROR_MESSAGE("strtoull");
136 /* Set up a minimal part of the system */
137 if (setup_locks(&conf
) < 0) {
141 if (setup_dbs(&conf
) < 0) {
145 if (setup_write_thread(&conf
) < 0) {
149 if (db_is_op(board_idx
, post_id
, &actually_is_op
) < 0) {
153 if (lock_acquire(board_idx
) < 0) {
157 if (actually_is_op
) {
158 if (db_remove_thread_and_files(board_idx
, post_id
) < 0) {
162 if (db_remove_post_and_files(board_idx
, post_id
) < 0) {
167 lock_release(board_idx
);
173 clean_write_thread();