--- lbbs/src/article_post.c 2025/06/15 03:16:44 1.16 +++ lbbs/src/article_post.c 2025/07/02 03:08:10 1.23 @@ -14,17 +14,15 @@ * * ***************************************************************************/ -#define _POSIX_C_SOURCE 200809L - -#include "article_post.h" #include "article_cache.h" -#include "editor.h" -#include "screen.h" +#include "article_post.h" #include "bbs.h" -#include "log.h" +#include "database.h" +#include "editor.h" #include "io.h" +#include "log.h" #include "lml.h" -#include "database.h" +#include "screen.h" #include "user_priv.h" #include #include @@ -110,6 +108,9 @@ int article_post(const SECTION_LIST *p_s { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); break; @@ -173,6 +174,9 @@ int article_post(const SECTION_LIST *p_s { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); case 'S': @@ -201,6 +205,11 @@ int article_post(const SECTION_LIST *p_s } } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { @@ -378,6 +387,9 @@ int article_post(const SECTION_LIST *p_s goto cleanup; } + mysql_close(db); + db = NULL; + clearscr(); moveto(1, 1); prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); @@ -471,7 +483,7 @@ int article_modify(const SECTION_LIST *p content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; // Remove control sequence - len_content = ctrl_seq_filter(content); + len_content = str_filter(content, 0); p_editor_data = editor_data_load(content); if (p_editor_data == NULL) @@ -503,6 +515,9 @@ int article_modify(const SECTION_LIST *p { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); case 'S': @@ -523,6 +538,11 @@ int article_modify(const SECTION_LIST *p } } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + // Allocate buffers in big size content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) @@ -653,6 +673,9 @@ int article_modify(const SECTION_LIST *p goto cleanup; } + mysql_close(db); + db = NULL; + clearscr(); moveto(1, 1); prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval); @@ -716,7 +739,7 @@ int article_reply(const SECTION_LIST *p_ p_article_new->title[0] = '\0'; snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); - len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len); + len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len, 0); title_input[len] = '\0'; db = db_open(); @@ -756,6 +779,9 @@ int article_reply(const SECTION_LIST *p_ if (topic_locked) // Reply is not allowed { + mysql_close(db); + db = NULL; + clearscr(); moveto(1, 1); prints("该主题谢绝回复"); @@ -806,19 +832,24 @@ int article_reply(const SECTION_LIST *p_ content_f[len] = '\0'; // Remove control sequence - len = ctrl_seq_filter(content_f); + len = str_filter(content_f, 0); len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, "\n\n【 在 %s (%s) 的大作中提到: 】\n", p_article->username, p_article->nickname); - quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1); + quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1, 0, NULL); for (i = 0; i < quote_content_lines; i++) { memcpy(content + len, ": ", 2); // quote line prefix len += 2; memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); len += (line_offsets[i + 1] - line_offsets[i]); + if (content[len - 1] != '\n') // Appennd \n if not exist + { + content[len] = '\n'; + len++; + } } if (content[len - 1] != '\n') // Appennd \n if not exist { @@ -872,6 +903,9 @@ int article_reply(const SECTION_LIST *p_ { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); break; @@ -929,6 +963,9 @@ int article_reply(const SECTION_LIST *p_ { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); case 'S': @@ -957,6 +994,11 @@ int article_reply(const SECTION_LIST *p_ } } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { @@ -1150,6 +1192,9 @@ int article_reply(const SECTION_LIST *p_ goto cleanup; } + mysql_close(db); + db = NULL; + clearscr(); moveto(1, 1); prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);