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.
27 #define PCRE2_CODE_UNIT_WIDTH 8
33 /* Global configuration */
34 const struct configuration
*conf
;
36 /* A template for pages 1, 2, ... of every board */
37 static char *board_page
;
38 static size_t board_page_len
;
40 /* A template for a particular thread's page */
41 static char *thread_page
;
42 static size_t thread_page_len
;
44 /* PCRE2 for parsing templates (pull out ${FOO}s) */
45 static pcre2_code
*variables
;
47 #define CHECK_FPRINTF(...) \
49 if (fprintf(__VA_ARGS__) < 0) { \
50 PERROR_MESSAGE("fprintf"); \
56 * Read in the contents of ${static_www_folder}/_templates/${local_name}
61 * - ${static_www_folder}/_templates/${local_name} is a readable folder.
65 * - Overwriting *out shall not cause a memory leak.
67 * Postconditions (success):
69 * - *out contains the full contents of
70 * ${static_www_folder}/_templates/${local_name}.
72 static int slurp_file(const char *local_name
, char **out
)
81 path_len
= snprintf(0, 0, "%s/_templates/%s", conf
->static_www_folder
,
84 if (!(path
= malloc(path_len
+ 1))) {
85 PERROR_MESSAGE("malloc");
89 sprintf(path
, "%s/_templates/%s", conf
->static_www_folder
, local_name
);
91 if (!(f
= fopen(path
, "r"))) {
92 ERROR_MESSAGE("cannot open \"%s\"", path
);
93 PERROR_MESSAGE("fopen");
97 fseek(f
, 0, SEEK_END
);
100 if (!(*out
= malloc(len
+ 1))) {
101 PERROR_MESSAGE("malloc");
105 fseek(f
, 0, SEEK_SET
);
107 /* XXX: can fread return short except on failure? */
108 if (fread(*out
, 1, len
, f
) < len
) {
109 PERROR_MESSAGE("fread");
126 * Initialize any static elements needed for this file
130 * - setup_write_thread() was not invoked more recently than
131 * clean_write_thread().
133 * Postconditions (success):
135 * - Any other function in this file may be safely called.
137 int setup_write_thread(const struct configuration
*in_conf
)
141 if (slurp_file("board_page", &board_page
) < 0) {
145 board_page_len
= strlen(board_page
);
147 if (slurp_file("thread_page", &thread_page
) < 0) {
151 thread_page_len
= strlen(thread_page
);
153 PCRE2_SIZE err_offset
= 0;
154 PCRE2_UCHAR8 err_buf
[120];
155 const char *variable_pattern_str
= "[$][{](?<var>[^}]+)[}]";
157 if (!(variables
= pcre2_compile((PCRE2_SPTR8
) variable_pattern_str
,
158 PCRE2_ZERO_TERMINATED
, PCRE2_UTF
,
159 &err_code
, &err_offset
, 0))) {
160 pcre2_get_error_message(err_code
, err_buf
, 120);
161 ERROR_MESSAGE("pcre2_compile: error with pattern \"%s\": %s",
162 variable_pattern_str
, err_buf
);
171 * Delete files which are in static_www_folder. Note that "full"
172 * means "the full file", not "the full path to the file". This is
177 * - system_full_path is a string of length system_full_path_len,
178 * something like "/m/src/4921183834.png".
180 * - system_thumb_path is a string of length system_thumb_path_len,
181 * something like "/m/src/4921183834.png".
183 * - As an exception, system_full_path and system_thumb_path may
184 * be 0 if their respective lengths are 0.
186 * - There is at most one board to which system_full_path and
187 * system_thumb_path are associated. For that board, THE LOCK
190 * Postconditions (success):
192 * - Those files have been unlink()'d.
194 int wt_remove_files(const char *system_full_path
, size_t system_full_path_len
,
195 const char *system_thumb_path
, size_t system_thumb_path_len
)
198 char *abs_full_path
= 0;
199 size_t abs_full_path_len
= 0;
200 char *abs_thumb_path
= 0;
201 size_t abs_thumb_path_len
= 0;
204 if (!system_full_path_len
) {
208 abs_full_path_len
= snprintf(0, 0, "%s%s", conf
->static_www_folder
,
211 if (!(abs_full_path
= malloc(abs_full_path_len
+ 1))) {
212 PERROR_MESSAGE("malloc");
216 sprintf(abs_full_path
, "%s%s", conf
->static_www_folder
,
219 if (unlink(abs_full_path
) < 0) {
220 PERROR_MESSAGE("unlink");
221 ERROR_MESSAGE("Failed to unlink(\"%s\")", abs_full_path
);
227 if (!system_thumb_path_len
) {
228 goto done_with_thumb
;
231 for (j
= 0; j
< conf
->filetypes_num
; ++j
) {
232 const struct filetype
*f
= &conf
->filetypes
[j
];
234 if (f
->static_thumbnail
&&
235 !strcmp(f
->static_thumbnail
, system_thumb_path
)) {
236 goto done_with_thumb
;
240 abs_thumb_path_len
= snprintf(0, 0, "%s%s", conf
->static_www_folder
,
243 if (!(abs_thumb_path
= malloc(abs_thumb_path_len
+ 1))) {
244 PERROR_MESSAGE("malloc");
248 sprintf(abs_thumb_path
, "%s%s", conf
->static_www_folder
,
251 if (unlink(abs_thumb_path
) < 0) {
252 PERROR_MESSAGE("unlink");
253 ERROR_MESSAGE("Failed to unlink(\"%s\")", abs_thumb_path
);
261 free(abs_thumb_path
);
267 * Delete files which are in static_www_folder. Note that "full"
268 * means "the full file", not "the full path to the file". This is
273 * - board_idx represents a board, AND THE LOCK IS HELD.
275 * - There is a page for thread_id up, e.g. at
276 * ${static_www_folder}/m/res/${thread_id}/index.html.
278 * Postconditions (success):
280 * - The folder for thread id (e.g.
281 * ${static_www_folder}/m/res/${thread_id}) no longer exists.
283 int wt_remove_thread_page(size_t board_idx
, uintmax_t thread_id
)
286 char *index_path
= 0;
287 char *folder_path
= 0;
288 size_t len
= snprintf(0, 0, "%s/%s/res/%ju/index.html",
289 conf
->static_www_folder
,
290 conf
->boards
[board_idx
].name
, thread_id
);
292 if (!(index_path
= malloc(len
+ 1))) {
293 PERROR_MESSAGE("malloc");
297 sprintf(index_path
, "%s/%s/res/%ju/index.html", conf
->static_www_folder
,
298 conf
->boards
[board_idx
].name
, thread_id
);
300 if (unlink(index_path
) < 0) {
301 PERROR_MESSAGE("unlink");
302 ERROR_MESSAGE("Failed to unlink(\"%s\")", index_path
);
306 if (!(folder_path
= malloc(len
+ 1))) {
307 PERROR_MESSAGE("malloc");
311 sprintf(folder_path
, "%s/%s/res/%ju", conf
->static_www_folder
,
312 conf
->boards
[board_idx
].name
, thread_id
);
314 if (rmdir(folder_path
) < 0) {
315 PERROR_MESSAGE("rmdir");
316 ERROR_MESSAGE("Failed to rmdir(\"%s\")", folder_path
);
329 * Write out the HTML file for a board
333 * - setup_write_thread() has been called more recently than
334 * clean_write_thread().
336 * - board_idx represents a board, AND THE LOCK IS HELD.
338 * - thread_ids is an array of length thread_ids_num.
340 * - Each element of thread_ids represents a thread.
342 * - thread_ids is sorted by bump order, most recent thread first.
344 * Postconditions (success):
346 * - Files at ${static_www_folder}/${board}/${n}/index.html
347 * has been written out, representing the current state of the
348 * board thread, for n = 0 to however many there should be.
350 int wt_write_board(size_t board_idx
, uintmax_t *thread_ids
, size_t
351 thread_ids_num
, size_t board_pages_num
)
357 pcre2_match_data
*match_data
= 0;
358 PCRE2_UCHAR
*var_name
= 0;
359 uint_fast8_t more_left_to_delete
= 1;
362 /* 3 capture groups: more than sufficient for ${foo} */
363 if (!(match_data
= pcre2_match_data_create(3, 0))) {
364 PERROR_MESSAGE("pcre2_match_data_create");
368 len
= snprintf(0, 0, "%s/%s/%zu/index.html", conf
->static_www_folder
,
369 conf
->boards
[board_idx
].name
, (size_t) -1);
371 if (!(path
= malloc(len
+ 1))) {
372 PERROR_MESSAGE("malloc");
376 /* First, delete all the pages we won't need */
379 * XXX: should we really be rmdir()ing? Can't we just leave
380 * the old directories around?
382 j
= board_pages_num
? board_pages_num
: 1;
384 while (j
!= (size_t) -1 &&
385 more_left_to_delete
) {
386 sprintf(path
, "%s/%s/%zu/index.html", conf
->static_www_folder
,
387 conf
->boards
[board_idx
].name
, j
);
389 if (unlink(path
) < 0) {
390 if (errno
== ENOENT
) {
391 more_left_to_delete
= 0;
395 PERROR_MESSAGE("unlink");
396 ERROR_MESSAGE("Failed to unlink(\"%s\")", path
);
400 sprintf(path
, "%s/%s/%zu", conf
->static_www_folder
,
401 conf
->boards
[board_idx
].name
, j
);
403 if (rmdir(path
) < 0) {
404 PERROR_MESSAGE("rmdir");
405 ERROR_MESSAGE("Failed to rmdir(\"%s\")", path
);
412 /* Now build the pages we do need */
413 for (size_t current_page
= 0; !current_page
||
414 (current_page
< board_pages_num
); ++current_page
) {
416 size_t match_pos
= 0;
417 size_t after_match_pos
= 0;
419 PCRE2_SIZE var_name_len
= 0;
420 size_t challenge_id
= rand() % conf
->challenges_num
;
421 size_t first_thread_idx
= current_page
*
422 conf
->boards
[board_idx
].
424 size_t num_threads_this_page
=
425 conf
->boards
[board_idx
].threads_per_page
;
427 if (first_thread_idx
+ num_threads_this_page
>=
429 num_threads_this_page
= thread_ids_num
-
434 sprintf(path
, "%s/%s/%zu", conf
->static_www_folder
,
435 conf
->boards
[board_idx
].name
, current_page
);
438 /* Make the directory. We shouldn't need mkdir -p. */
439 if (mkdir(path
, 0755) < 0) {
440 if (errno
!= EEXIST
) {
441 PERROR_MESSAGE("mkdir");
442 ERROR_MESSAGE("mkdir(\"%s\") failed",
448 /* Now open the file */
449 sprintf(path
, "%s/%s/%zu/index.html",
450 conf
->static_www_folder
,
451 conf
->boards
[board_idx
].name
,
454 sprintf(path
, "%s/%s/index.html",
455 conf
->static_www_folder
,
456 conf
->boards
[board_idx
].name
);
463 if (!(f
= fopen(path
, "w"))) {
464 PERROR_MESSAGE("fopen");
465 ERROR_MESSAGE("fopen(\"%s\", \"w\") failed", path
);
472 if (idx
>= board_page_len
) {
476 /* Where does ${FOO} appear next? */
477 nret
= pcre2_match(variables
, (PCRE2_SPTR
) board_page
,
478 board_page_len
, idx
, 0, match_data
, 0);
480 if (nret
== PCRE2_ERROR_NOMATCH
) {
481 CHECK_FPRINTF(f
, "%s", board_page
+ idx
);
486 PCRE2_UCHAR8 err_buf
[120];
488 pcre2_get_error_message(nret
, err_buf
, 120);
490 "pcre2_match: error while matching \"%.*s\": %s"
491 " (PCRE2 %d)", (int) (board_page_len
- idx
),
492 board_page
+ idx
, err_buf
, nret
);
497 pcre2_substring_free(var_name
);
501 if ((nret
= pcre2_substring_get_byname(match_data
,
505 PCRE2_UCHAR8 err_buf
[120];
507 pcre2_get_error_message(nret
, err_buf
, 120);
509 "pcre2_substring_get_byname: %s (PCRE2 %d)",
515 match_pos
= pcre2_get_ovector_pointer(match_data
)[0];
516 after_match_pos
= pcre2_get_ovector_pointer(match_data
)[1];
517 CHECK_FPRINTF(f
, "%.*s", (int) (match_pos
- idx
), board_page
+
521 if (!strncasecmp((const char *) var_name
, "BOARD",
523 CHECK_FPRINTF(f
, "%s", conf
->boards
[board_idx
].name
);
524 } else if (!strncasecmp((const char *) var_name
, "BOARD_TITLE",
526 CHECK_FPRINTF(f
, "%s", conf
->boards
[board_idx
].title
);
527 } else if (!strncasecmp((const char *) var_name
, "CHALLENGE",
529 CHECK_FPRINTF(f
, "%s",
530 conf
->challenges
[challenge_id
].question
);
531 } else if (!strncasecmp((const char *) var_name
, "CHALLENGE_ID",
533 CHECK_FPRINTF(f
, "%zu", challenge_id
);
534 } else if (!strncasecmp((const char *) var_name
, "PAGELINKS",
536 CHECK_FPRINTF(f
, "[<a href=\"/%s\">0</a>] ",
537 conf
->boards
[board_idx
].name
);
539 for (size_t j
= 1; j
< board_pages_num
; ++j
) {
541 "[<a href=\"/%s/%zu\">%zu</a>] ",
542 conf
->boards
[board_idx
].name
, j
,
545 } else if (!strncasecmp((const char *) var_name
,
546 "RANDOM_HEADER", var_name_len
)) {
547 CHECK_FPRINTF(f
, "%s", conf
->headers
[rand() %
549 } else if (!strncasecmp((const char *) var_name
, "THREADS",
552 * We have to transfer control to db-ZZZ
553 * for a bit - it comes back through
556 db_writeback_thread_summaries(board_idx
, thread_ids
+
558 num_threads_this_page
, f
);
560 CHECK_FPRINTF(f
, "${%.*s}", (int) var_name_len
,
564 idx
= after_match_pos
;
572 pcre2_match_data_free(match_data
);
573 pcre2_substring_free(var_name
);
585 * Write p out to f as the first post of a thread.
587 * This function is intended to be called by
588 * db_writeback_posts_in_thread(), which is called from wt_write_thread().
592 * - setup_write_thread() has been called more recently than
593 * clean_write_thread().
595 * - p is a fully filled stored_post (i.e. from a row in the database).
597 * - f is an open, writable FILE *.
599 * - board_idx represents a baord.
601 * - If is_summary is not zero, then board_name is a string like
602 * "m" or "sf". Furthermore, if is_op is also not zero, then
603 * total_posts_in_thread is a number suitable for describing the
606 * Postconditions (success):
608 * - the contents of p have been written to f, which returned no
609 * errors. The format is not precisely defined.
611 int wt_write_post(struct prepared_post
*p
, FILE *f
, uint_fast8_t is_op
,
612 uint_fast8_t is_summary
, const char *board_name
, uintmax_t
613 total_posts_in_thread
, uint_fast8_t hr_before
)
616 char *human_readable_time
= util_iso8601_from_time_t(p
->now
);
618 if (!human_readable_time
) {
619 ERROR_MESSAGE("util_iso_8601_from_time(%ju) failed",
624 /* XXX: make sure this looks decent, both in ff and elinks */
625 CHECK_FPRINTF(f
, "<hr />");
629 CHECK_FPRINTF(f
, "<div class=\"op-post\" id=\"post%ju\">",
632 CHECK_FPRINTF(f
, "<div class=\"reply-post\" id=\"post%ju\">",
636 CHECK_FPRINTF(f
, "<table><tr>");
637 CHECK_FPRINTF(f
, "<td colspan=\"2\">");
638 CHECK_FPRINTF(f
, "<div class=\"post-info\">");
640 if (p
->subject_len
) {
641 CHECK_FPRINTF(f
, "<span class=\"post-subject\">%.*s</span> ",
642 (int) p
->subject_len
, p
->subject
);
647 CHECK_FPRINTF(f
, "<a href=\"mailto:%.*s\">",
648 (int) p
->email_len
, p
->email
);
651 CHECK_FPRINTF(f
, "<span class=\"post-author\">%.*s</span>",
652 (int) p
->name_len
, p
->name
);
655 CHECK_FPRINTF(f
, "</a>");
658 if (p
->tripcode_len
) {
659 CHECK_FPRINTF(f
, "<span class=\"post-tripcode\">");
660 CHECK_FPRINTF(f
, "!%.*s</span>", (int) p
->tripcode_len
,
665 CHECK_FPRINTF(f
, " <span class=\"post-time\">%s</span>",
666 human_readable_time
? human_readable_time
: "NEVER");
667 CHECK_FPRINTF(f
, " <span class=\"post-number\">No. %ju</span>", p
->id
);
670 if (p
->thread_closed
) {
671 CHECK_FPRINTF(f
, " <span class=\"thread-closed\">");
672 CHECK_FPRINTF(f
, "Closed</span>");
675 if (p
->thread_stickied
) {
676 CHECK_FPRINTF(f
, " <span class=\"thread-stickied\">");
677 CHECK_FPRINTF(f
, "Sticky</span>");
683 CHECK_FPRINTF(f
, " [<a href=\"/%s/res/%ju\">View</a>]",
687 CHECK_FPRINTF(f
, "</div></td></tr>");
689 if (p
->system_full_path_len
) {
690 CHECK_FPRINTF(f
, "<tr><td colspan=\"2\">");
691 CHECK_FPRINTF(f
, "<span class=\"file-info\">");
692 CHECK_FPRINTF(f
, "<a class=\"filelink\" href=\"%.*s\">",
693 (int) p
->system_full_path_len
,
694 p
->system_full_path
);
695 CHECK_FPRINTF(f
, "%.*s", (int) p
->file_name_len
, p
->file_name
);
696 CHECK_FPRINTF(f
, "</a>");
697 CHECK_FPRINTF(f
, " (%.*s)</span></td></tr><tr>",
698 (int) p
->file_info_len
, p
->file_info
);
699 CHECK_FPRINTF(f
, "<td class=\"thin\">");
700 CHECK_FPRINTF(f
, "<a class=\"filelink\" href=\"%.*s\">",
701 (int) p
->system_full_path_len
,
702 p
->system_full_path
);
703 CHECK_FPRINTF(f
, "<img src=\"%.*s\" alt=\"image\" ",
704 (int) p
->system_thumb_path_len
,
705 p
->system_thumb_path
);
706 CHECK_FPRINTF(f
, "class=\"thumb\"/>");
707 CHECK_FPRINTF(f
, "</a></td>");
709 CHECK_FPRINTF(f
, "<tr><td class=\"thin\"> </td>");
712 CHECK_FPRINTF(f
, "<td>");
713 CHECK_FPRINTF(f
, "<div class=\"post-comment\">");
714 CHECK_FPRINTF(f
, "%.*s", (int) p
->comment_len
, p
->comment
);
715 CHECK_FPRINTF(f
, "</div>");
716 CHECK_FPRINTF(f
, "</td></tr></table></div>");
720 CHECK_FPRINTF(f
, "<div class=\"reply-count-info\">");
721 CHECK_FPRINTF(f
, "%ju post%s in thread. ",
722 total_posts_in_thread
, (total_posts_in_thread
==
724 CHECK_FPRINTF(f
, "<a href=\"/%s/res/%ju\">View thread</a>",
726 CHECK_FPRINTF(f
, "</div>");
731 free(human_readable_time
);
737 * Write out the HTML file for a thread
741 * - setup_write_thread() has been called more recently than
742 * clean_write_thread().
744 * - board_idx represents a board, AND THE LOCK IS HELD.
746 * - thread is the post_id of a thread.
748 * Postconditions (success):
750 * - A file at ${static_www_folder}/${board}/res/${thread}/index.html
751 * has been written out, representing the recent state of the
754 int wt_write_thread(size_t board_idx
, uintmax_t thread
)
758 size_t match_pos
= 0;
759 size_t after_match_pos
= 0;
760 pcre2_match_data
*match_data
= 0;
764 char *index_path
= 0;
765 PCRE2_UCHAR
*var_name
= 0;
766 PCRE2_SIZE var_name_len
= 0;
767 size_t challenge_id
= rand() % conf
->challenges_num
;
769 len
= snprintf(0, 0, "%s/%s/res/%ju/index.html",
770 conf
->static_www_folder
, conf
->boards
[board_idx
].name
,
773 if (!(index_path
= malloc(len
+ 1))) {
774 PERROR_MESSAGE("malloc");
778 sprintf(index_path
, "%s/%s/res/%ju", conf
->static_www_folder
,
779 conf
->boards
[board_idx
].name
, thread
);
782 /* Make the directory. We shouldn't need mkdir -p. */
783 if (mkdir(index_path
, 0755) < 0) {
784 if (errno
!= EEXIST
) {
785 PERROR_MESSAGE("mkdir");
786 ERROR_MESSAGE("mkdir(\"%s\") failed", index_path
);
791 /* Now open the file */
792 sprintf(index_path
, "%s/%s/res/%ju/index.html", conf
->static_www_folder
,
793 conf
->boards
[board_idx
].name
, thread
);
795 if (!(f
= fopen(index_path
, "w"))) {
796 PERROR_MESSAGE("fopen");
797 ERROR_MESSAGE("fopen(\"%s\", \"w\") failed", index_path
);
801 /* 3 capture groups: more than sufficient for ${foo} */
802 if (!(match_data
= pcre2_match_data_create(3, 0))) {
803 PERROR_MESSAGE("pcre2_match_data_create");
810 if (idx
>= thread_page_len
) {
814 /* Where does ${FOO} appear next? */
815 nret
= pcre2_match(variables
, (PCRE2_SPTR
) thread_page
, thread_page_len
,
816 idx
, 0, match_data
, 0);
818 if (nret
== PCRE2_ERROR_NOMATCH
) {
819 CHECK_FPRINTF(f
, "%s", thread_page
+ idx
);
824 PCRE2_UCHAR8 err_buf
[120];
826 pcre2_get_error_message(nret
, err_buf
, 120);
827 ERROR_MESSAGE("pcre2_match: error while matching \"%.*s\": %s"
828 " (PCRE2 %d)", (int) (thread_page_len
- idx
),
835 pcre2_substring_free(var_name
);
839 if ((nret
= pcre2_substring_get_byname(match_data
, (PCRE2_SPTR
) "var",
840 &var_name
, &var_name_len
))) {
841 PCRE2_UCHAR8 err_buf
[120];
843 pcre2_get_error_message(nret
, err_buf
, 120);
844 ERROR_MESSAGE("pcre2_substring_get_byname: %s (PCRE2 %d)",
849 match_pos
= pcre2_get_ovector_pointer(match_data
)[0];
850 after_match_pos
= pcre2_get_ovector_pointer(match_data
)[1];
851 CHECK_FPRINTF(f
, "%.*s", (int) (match_pos
- idx
), thread_page
+ idx
);
854 if (!strncasecmp((const char *) var_name
, "BOARD", var_name_len
)) {
855 CHECK_FPRINTF(f
, "%s", conf
->boards
[board_idx
].name
);
856 } else if (!strncasecmp((const char *) var_name
, "BOARD_TITLE",
858 CHECK_FPRINTF(f
, "%s", conf
->boards
[board_idx
].title
);
859 } else if (!strncasecmp((const char *) var_name
, "CHALLENGE",
861 CHECK_FPRINTF(f
, "%s", conf
->challenges
[challenge_id
].question
);
862 } else if (!strncasecmp((const char *) var_name
, "CHALLENGE_ID",
864 CHECK_FPRINTF(f
, "%zu", challenge_id
);
865 } else if (!strncasecmp((const char *) var_name
, "OP_SUBJECT",
868 size_t subject_len
= 0;
870 if (db_extract_subject(board_idx
, thread
, &subject
,
876 CHECK_FPRINTF(f
, "%.*s", (int) subject_len
, subject
);
880 } else if (!strncasecmp((const char *) var_name
, "RANDOM_HEADER",
882 CHECK_FPRINTF(f
, "%s", conf
->headers
[rand() %
884 } else if (!strncasecmp((const char *) var_name
, "THREAD_NUMBER",
886 CHECK_FPRINTF(f
, "%zu", thread
);
887 } else if (!strncasecmp((const char *) var_name
, "POSTS",
890 * We have to transfer control to db-ZZZ for a bit
891 * - it comes back through wt_write_post().
893 db_writeback_posts_in_thread(board_idx
, thread
, f
,
896 CHECK_FPRINTF(f
, "${%.*s}", (int) var_name_len
, var_name
);
899 idx
= after_match_pos
;
904 pcre2_match_data_free(match_data
);
905 pcre2_substring_free(var_name
);
917 * Clean any memory from this file
919 * Postconditions (success):
921 * - Valgrind won't report any memory leaks from this file.
923 * - setup_write_thread() can be safely called again.
925 void clean_write_thread(void)
934 pcre2_code_free(variables
);