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.
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 .temp_dir_template
= temp_dir_template
, /* */
95 .trip_salt
= trip_salt
, /* */
96 .trip_salt_len
= strlen(trip_salt
), /* */
97 .boards
= boards
, /* */
98 .boards_num
= NUM_OF(boards
), /* */
99 .max_form_data_size
= max_form_data_size
, /* */
100 .max_file_size
= max_file_size
, /* */
101 .max_text_len
= max_text_len
, /* */
102 .filetypes
= filetypes
, /* */
103 .filetypes_num
= NUM_OF(filetypes
), /* */
104 .file_description_prog
= file_description_prog
, /* */
105 .headers
= headers
, /* */
106 .headers_num
= NUM_OF(headers
), /* */
107 .challenges
= challenges
, /* */
108 .challenges_num
= NUM_OF(challenges
), /* */
109 .wordfilter_inputs
= wordfilter_inputs
, /* */
110 .wordfilter_inputs_num
= NUM_OF(wordfilter_inputs
), /* */
113 /* Interpret board */
114 board_idx
= (size_t) -1;
116 for (size_t j
= 0; j
< conf
.boards_num
; ++j
) {
117 if (!strcmp(conf
.boards
[j
].name
, b_arg
)) {
122 if (board_idx
== (size_t) -1) {
123 ERROR_MESSAGE("No board \"%s\" known", b_arg
);
129 post_id
= strtoull(p_arg
, 0, 0);
133 PERROR_MESSAGE("strtoull");
137 /* Set up a minimal part of the system */
138 if (setup_locks(&conf
) < 0) {
142 if (setup_dbs(&conf
) < 0) {
146 if (setup_write_thread(&conf
) < 0) {
150 if (db_is_op(board_idx
, post_id
, &actually_is_op
) < 0) {
154 if (lock_acquire(board_idx
) < 0) {
158 if (actually_is_op
) {
159 if (db_remove_thread_and_files(board_idx
, post_id
) < 0) {
163 if (db_remove_post_and_files(board_idx
, post_id
) < 0) {
168 lock_release(board_idx
);
174 clean_write_thread();