2 * Copyright (c) 2017-2020, 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-view-thread";
35 static uint_fast8_t use_color
= 1;
37 /* Show usage message, do not exit */
41 size_t len
= strlen(program_name
);
43 printf("Usage: %s -b board-name\n", program_name
);
44 printf(" %*s -t thread-id\n", (int) len
, "");
45 printf(" %*s [ -C ] # Do not use color\n", (int) len
, "");
48 /* Print out enough of a post to give the mod information */
50 print_post(struct prepared_post
*p
, FILE *f
, uint_fast8_t is_op
, uint_fast8_t
51 is_summary
, uint_fast8_t is_recent
, const char *board_name
, uintmax_t
53 uintmax_t total_posts_in_thread
, uint_fast8_t hr_before
)
55 char *time_str
= util_iso8601_from_time_t(p
->now
);
56 unsigned char out_hash
[9] = { 0 };
63 UNUSED(total_posts_in_thread
);
65 if (crypto_generichash(out_hash
, 9, (const unsigned char *) p
->ip
,
67 PERROR_MESSAGE("crypto_generichash_init");
72 fprintf(f
, "--------------------------------------\n");
78 fprintf(f
, "\033[48;2;%d;%d;%dm ", 0xff & out_hash
[0], 0xff &
79 out_hash
[1], 0xff & out_hash
[2]);
80 fprintf(f
, "\033[48;2;%d;%d;%dm ", 0xff & out_hash
[3], 0xff &
81 out_hash
[4], 0xff & out_hash
[5]);
82 fprintf(f
, "\033[48;2;%d;%d;%dm ", 0xff & out_hash
[6], 0xff &
83 out_hash
[7], 0xff & out_hash
[8]);
84 fprintf(f
, "\033[0m");
89 fprintf(f
, " %s%*s", p
->ip
, (int) (20 > p
->ip_len
? 20 - p
->ip_len
: 1),
91 fprintf(f
, "%s ", UBSAFES(time_str
));
92 fprintf(f
, "No. %ju\n", p
->id
);
95 fprintf(f
, " [ File: %s ]\n", p
->file_name
);
100 if (p
->comment_len
> 40) {
101 fprintf(f
, "%.*s...", 37, p
->comment
);
102 } else if (p
->comment_len
) {
103 fprintf(f
, "%s", p
->comment
);
107 fprintf(f
, "--------------------------------------\n");
116 main(int argc
, char **argv
)
119 struct configuration conf
= { 0 };
121 const char *b_arg
= 0;
122 size_t board_idx
= 0;
123 const char *t_arg
= 0;
124 uintmax_t thread_id
= 0;
126 setlocale(LC_ALL
, "");
129 while ((opt
= getopt(argc
, argv
, "b:t:C")) != -1) {
134 ERROR_MESSAGE("-b already specified");
143 ERROR_MESSAGE("-t already specified");
164 conf
= (struct configuration
) {
166 .static_www_folder
= static_www_folder
, /* */
167 .work_path
= work_path
, /* */
168 .temp_dir_template
= temp_dir_template
, /* */
169 .trip_salt
= trip_salt
, /* */
170 .trip_salt_len
= strlen(trip_salt
), /* */
171 .boards
= boards
, /* */
172 .boards_num
= NUM_OF(boards
), /* */
173 .max_form_data_size
= max_form_data_size
, /* */
174 .max_file_size
= max_file_size
, /* */
175 .max_text_len
= max_text_len
, /* */
176 .filetypes
= filetypes
, /* */
177 .filetypes_num
= NUM_OF(filetypes
), /* */
178 .file_description_prog
= file_description_prog
, /* */
179 .headers
= headers
, /* */
180 .headers_num
= NUM_OF(headers
), /* */
181 .challenges
= challenges
, /* */
182 .challenges_num
= NUM_OF(challenges
), /* */
183 .wordfilter_inputs
= wordfilter_inputs
, /* */
184 .wordfilter_inputs_num
= NUM_OF(wordfilter_inputs
), /* */
185 .forbidden_inputs
= forbidden_inputs
, /* */
186 .forbidden_inputs_num
= NUM_OF(forbidden_inputs
), /* */
189 /* Interpret board */
190 board_idx
= (size_t) -1;
192 for (size_t j
= 0; j
< conf
.boards_num
; ++j
) {
193 if (!strcmp(conf
.boards
[j
].name
, b_arg
)) {
198 if (board_idx
== (size_t) -1) {
199 ERROR_MESSAGE("No board \"%s\" known", b_arg
);
203 /* Interpret thread */
205 thread_id
= strtoull(t_arg
, 0, 0);
209 PERROR_MESSAGE("strtoull");
213 /* Set up a minimal part of the system */
214 if (setup_locks(&conf
) < 0) {
218 if (setup_dbs(&conf
) < 0) {
222 if (setup_write_thread(&conf
) < 0) {
226 ret
= db_writeback_posts_in_thread(board_idx
, thread_id
, stdout
,
231 clean_write_thread();