| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
|
|
|
| 17 |
#include "article_post.h" |
#include "article_post.h" |
| 18 |
#include "article_cache.h" |
#include "article_cache.h" |
| 19 |
#include "editor.h" |
#include "editor.h" |
| 79 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 80 |
{ |
{ |
| 81 |
log_error("editor_data_load() error\n"); |
log_error("editor_data_load() error\n"); |
| 82 |
return -2; |
ret = -1; |
| 83 |
|
goto cleanup; |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
// Set title and sign |
// Set title and sign |
| 108 |
{ |
{ |
| 109 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 110 |
{ |
{ |
| 111 |
|
case KEY_NULL: |
| 112 |
|
case KEY_TIMEOUT: |
| 113 |
|
goto cleanup; |
| 114 |
case CR: |
case CR: |
| 115 |
igetch_reset(); |
igetch_reset(); |
| 116 |
break; |
break; |
| 174 |
{ |
{ |
| 175 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 176 |
{ |
{ |
| 177 |
|
case KEY_NULL: |
| 178 |
|
case KEY_TIMEOUT: |
| 179 |
|
goto cleanup; |
| 180 |
case CR: |
case CR: |
| 181 |
igetch_reset(); |
igetch_reset(); |
| 182 |
case 'S': |
case 'S': |
| 205 |
} |
} |
| 206 |
} |
} |
| 207 |
|
|
| 208 |
|
if (SYS_server_exit) // Do not save data on shutdown |
| 209 |
|
{ |
| 210 |
|
goto cleanup; |
| 211 |
|
} |
| 212 |
|
|
| 213 |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 214 |
if (content == NULL) |
if (content == NULL) |
| 215 |
{ |
{ |
| 222 |
if (len_content < 0) |
if (len_content < 0) |
| 223 |
{ |
{ |
| 224 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 225 |
ret = -2; |
ret = -1; |
| 226 |
goto cleanup; |
goto cleanup; |
| 227 |
} |
} |
| 228 |
|
|
| 387 |
goto cleanup; |
goto cleanup; |
| 388 |
} |
} |
| 389 |
|
|
| 390 |
|
mysql_close(db); |
| 391 |
|
db = NULL; |
| 392 |
|
|
| 393 |
clearscr(); |
clearscr(); |
| 394 |
moveto(1, 1); |
moveto(1, 1); |
| 395 |
prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); |
prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); |
| 442 |
return 0; |
return 0; |
| 443 |
} |
} |
| 444 |
|
|
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) |
|
|
{ |
|
|
clearscr(); |
|
|
moveto(1, 1); |
|
|
prints("您没有权限在本版块发表文章\n"); |
|
|
press_any_key(); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
| 445 |
db = db_open(); |
db = db_open(); |
| 446 |
if (db == NULL) |
if (db == NULL) |
| 447 |
{ |
{ |
| 448 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 449 |
return -1; |
ret = -1; |
| 450 |
|
goto cleanup; |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 459 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 460 |
{ |
{ |
| 461 |
log_error("Query article content error: %s\n", mysql_error(db)); |
log_error("Query article content error: %s\n", mysql_error(db)); |
| 462 |
ret = -2; |
ret = -1; |
| 463 |
goto cleanup; |
goto cleanup; |
| 464 |
} |
} |
| 465 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 466 |
{ |
{ |
| 467 |
log_error("Get article content data failed\n"); |
log_error("Get article content data failed\n"); |
| 468 |
ret = -2; |
ret = -1; |
| 469 |
goto cleanup; |
goto cleanup; |
| 470 |
} |
} |
| 471 |
|
|
| 483 |
content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; |
content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; |
| 484 |
|
|
| 485 |
// Remove control sequence |
// Remove control sequence |
| 486 |
len_content = ctrl_seq_filter(content); |
len_content = str_filter(content, 0); |
| 487 |
|
|
| 488 |
p_editor_data = editor_data_load(content); |
p_editor_data = editor_data_load(content); |
| 489 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 490 |
{ |
{ |
| 491 |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
| 492 |
ret = -3; |
ret = -1; |
| 493 |
goto cleanup; |
goto cleanup; |
| 494 |
} |
} |
| 495 |
|
|
| 515 |
{ |
{ |
| 516 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 517 |
{ |
{ |
| 518 |
|
case KEY_NULL: |
| 519 |
|
case KEY_TIMEOUT: |
| 520 |
|
goto cleanup; |
| 521 |
case CR: |
case CR: |
| 522 |
igetch_reset(); |
igetch_reset(); |
| 523 |
case 'S': |
case 'S': |
| 538 |
} |
} |
| 539 |
} |
} |
| 540 |
|
|
| 541 |
|
if (SYS_server_exit) // Do not save data on shutdown |
| 542 |
|
{ |
| 543 |
|
goto cleanup; |
| 544 |
|
} |
| 545 |
|
|
| 546 |
// Allocate buffers in big size |
// Allocate buffers in big size |
| 547 |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 548 |
if (content == NULL) |
if (content == NULL) |
| 556 |
if (len_content < 0) |
if (len_content < 0) |
| 557 |
{ |
{ |
| 558 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 559 |
ret = -2; |
ret = -1; |
| 560 |
goto cleanup; |
goto cleanup; |
| 561 |
} |
} |
| 562 |
|
|
| 635 |
|
|
| 636 |
// Update article |
// Update article |
| 637 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 638 |
"UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d", |
"UPDATE bbs SET CID = %d, length = %ld, excerption = 0 WHERE AID = %d", // Set excerption = 0 explictly in case of rare condition |
| 639 |
p_article_new->cid, len_content, p_article->aid); |
p_article_new->cid, len_content, p_article->aid); |
| 640 |
|
|
| 641 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 673 |
goto cleanup; |
goto cleanup; |
| 674 |
} |
} |
| 675 |
|
|
| 676 |
|
mysql_close(db); |
| 677 |
|
db = NULL; |
| 678 |
|
|
| 679 |
clearscr(); |
clearscr(); |
| 680 |
moveto(1, 1); |
moveto(1, 1); |
| 681 |
prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval); |
prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval); |
| 720 |
long quote_content_lines; |
long quote_content_lines; |
| 721 |
long i; |
long i; |
| 722 |
long ret = 0; |
long ret = 0; |
| 723 |
|
int topic_locked = 0; |
| 724 |
|
|
| 725 |
if (p_section == NULL || p_article == NULL) |
if (p_section == NULL || p_article == NULL) |
| 726 |
{ |
{ |
| 737 |
return 0; |
return 0; |
| 738 |
} |
} |
| 739 |
|
|
|
if (p_article->lock) // Reply is not allowed |
|
|
{ |
|
|
clearscr(); |
|
|
moveto(1, 1); |
|
|
prints("该文章谢绝回复"); |
|
|
press_any_key(); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
| 740 |
p_article_new->title[0] = '\0'; |
p_article_new->title[0] = '\0'; |
| 741 |
snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); |
snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); |
| 742 |
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); |
| 743 |
title_input[len] = '\0'; |
title_input[len] = '\0'; |
| 744 |
|
|
| 745 |
db = db_open(); |
db = db_open(); |
| 746 |
if (db == NULL) |
if (db == NULL) |
| 747 |
{ |
{ |
| 748 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 749 |
return -1; |
ret = -1; |
| 750 |
|
goto cleanup; |
| 751 |
|
} |
| 752 |
|
|
| 753 |
|
snprintf(sql, sizeof(sql), |
| 754 |
|
"SELECT `lock` FROM bbs WHERE AID = %d", |
| 755 |
|
(p_article->tid == 0 ? p_article->aid : p_article->tid)); |
| 756 |
|
|
| 757 |
|
if (mysql_query(db, sql) != 0) |
| 758 |
|
{ |
| 759 |
|
log_error("Query article status error: %s\n", mysql_error(db)); |
| 760 |
|
ret = -1; |
| 761 |
|
goto cleanup; |
| 762 |
|
} |
| 763 |
|
if ((rs = mysql_store_result(db)) == NULL) |
| 764 |
|
{ |
| 765 |
|
log_error("Get article status data failed\n"); |
| 766 |
|
ret = -1; |
| 767 |
|
goto cleanup; |
| 768 |
|
} |
| 769 |
|
|
| 770 |
|
if ((row = mysql_fetch_row(rs))) |
| 771 |
|
{ |
| 772 |
|
if (atoi(row[0]) != 0) |
| 773 |
|
{ |
| 774 |
|
topic_locked = 1; |
| 775 |
|
} |
| 776 |
|
} |
| 777 |
|
mysql_free_result(rs); |
| 778 |
|
rs = NULL; |
| 779 |
|
|
| 780 |
|
if (topic_locked) // Reply is not allowed |
| 781 |
|
{ |
| 782 |
|
mysql_close(db); |
| 783 |
|
db = NULL; |
| 784 |
|
|
| 785 |
|
clearscr(); |
| 786 |
|
moveto(1, 1); |
| 787 |
|
prints("该主题谢绝回复"); |
| 788 |
|
press_any_key(); |
| 789 |
|
|
| 790 |
|
goto cleanup; |
| 791 |
} |
} |
| 792 |
|
|
| 793 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 799 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 800 |
{ |
{ |
| 801 |
log_error("Query article content error: %s\n", mysql_error(db)); |
log_error("Query article content error: %s\n", mysql_error(db)); |
| 802 |
return -2; |
ret = -1; |
| 803 |
|
goto cleanup; |
| 804 |
} |
} |
| 805 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 806 |
{ |
{ |
| 807 |
log_error("Get article content data failed\n"); |
log_error("Get article content data failed\n"); |
| 808 |
return -2; |
ret = -1; |
| 809 |
|
goto cleanup; |
| 810 |
} |
} |
| 811 |
|
|
| 812 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 832 |
content_f[len] = '\0'; |
content_f[len] = '\0'; |
| 833 |
|
|
| 834 |
// Remove control sequence |
// Remove control sequence |
| 835 |
len = ctrl_seq_filter(content_f); |
len = str_filter(content_f, 0); |
| 836 |
|
|
| 837 |
len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, |
len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, |
| 838 |
"\n\n【 在 %s (%s) 的大作中提到: 】\n", |
"\n\n【 在 %s (%s) 的大作中提到: 】\n", |
| 839 |
p_article->username, p_article->nickname); |
p_article->username, p_article->nickname); |
| 840 |
|
|
| 841 |
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); |
| 842 |
for (i = 0; i < quote_content_lines; i++) |
for (i = 0; i < quote_content_lines; i++) |
| 843 |
{ |
{ |
| 844 |
memcpy(content + len, ": ", 2); // quote line prefix |
memcpy(content + len, ": ", 2); // quote line prefix |
| 845 |
len += 2; |
len += 2; |
| 846 |
memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); |
memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); |
| 847 |
len += (line_offsets[i + 1] - line_offsets[i]); |
len += (line_offsets[i + 1] - line_offsets[i]); |
| 848 |
|
if (content[len - 1] != '\n') // Appennd \n if not exist |
| 849 |
|
{ |
| 850 |
|
content[len] = '\n'; |
| 851 |
|
len++; |
| 852 |
|
} |
| 853 |
} |
} |
| 854 |
if (content[len - 1] != '\n') // Appennd \n if not exist |
if (content[len - 1] != '\n') // Appennd \n if not exist |
| 855 |
{ |
{ |
| 865 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 866 |
{ |
{ |
| 867 |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
| 868 |
ret = -3; |
ret = -1; |
| 869 |
goto cleanup; |
goto cleanup; |
| 870 |
} |
} |
| 871 |
|
|
| 903 |
{ |
{ |
| 904 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 905 |
{ |
{ |
| 906 |
|
case KEY_NULL: |
| 907 |
|
case KEY_TIMEOUT: |
| 908 |
|
goto cleanup; |
| 909 |
case CR: |
case CR: |
| 910 |
igetch_reset(); |
igetch_reset(); |
| 911 |
break; |
break; |
| 963 |
{ |
{ |
| 964 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 965 |
{ |
{ |
| 966 |
|
case KEY_NULL: |
| 967 |
|
case KEY_TIMEOUT: |
| 968 |
|
goto cleanup; |
| 969 |
case CR: |
case CR: |
| 970 |
igetch_reset(); |
igetch_reset(); |
| 971 |
case 'S': |
case 'S': |
| 994 |
} |
} |
| 995 |
} |
} |
| 996 |
|
|
| 997 |
|
if (SYS_server_exit) // Do not save data on shutdown |
| 998 |
|
{ |
| 999 |
|
goto cleanup; |
| 1000 |
|
} |
| 1001 |
|
|
| 1002 |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 1003 |
if (content == NULL) |
if (content == NULL) |
| 1004 |
{ |
{ |
| 1011 |
if (len_content < 0) |
if (len_content < 0) |
| 1012 |
{ |
{ |
| 1013 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 1014 |
ret = -2; |
ret = -1; |
| 1015 |
goto cleanup; |
goto cleanup; |
| 1016 |
} |
} |
| 1017 |
|
|
| 1192 |
goto cleanup; |
goto cleanup; |
| 1193 |
} |
} |
| 1194 |
|
|
| 1195 |
|
mysql_close(db); |
| 1196 |
|
db = NULL; |
| 1197 |
|
|
| 1198 |
clearscr(); |
clearscr(); |
| 1199 |
moveto(1, 1); |
moveto(1, 1); |
| 1200 |
prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); |
prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); |