| 81 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 82 |
{ |
{ |
| 83 |
log_error("editor_data_load() error\n"); |
log_error("editor_data_load() error\n"); |
| 84 |
return -2; |
ret = -1; |
| 85 |
|
goto cleanup; |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
// Set title and sign |
// Set title and sign |
| 213 |
if (len_content < 0) |
if (len_content < 0) |
| 214 |
{ |
{ |
| 215 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 216 |
ret = -2; |
ret = -1; |
| 217 |
goto cleanup; |
goto cleanup; |
| 218 |
} |
} |
| 219 |
|
|
| 254 |
rs = NULL; |
rs = NULL; |
| 255 |
} |
} |
| 256 |
|
|
|
content_f = malloc((size_t)len_content * 2 + 1); |
|
|
if (content_f == NULL) |
|
|
{ |
|
|
log_error("malloc(content_f) error: OOM\n"); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
|
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
|
|
if (sql_content == NULL) |
|
|
{ |
|
|
log_error("malloc(sql_content) error: OOM\n"); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
| 257 |
// Begin transaction |
// Begin transaction |
| 258 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 259 |
{ |
{ |
| 270 |
} |
} |
| 271 |
|
|
| 272 |
// Secure SQL parameters |
// Secure SQL parameters |
| 273 |
|
content_f = malloc((size_t)len_content * 2 + 1); |
| 274 |
|
if (content_f == NULL) |
| 275 |
|
{ |
| 276 |
|
log_error("malloc(content_f) error: OOM\n"); |
| 277 |
|
ret = -1; |
| 278 |
|
goto cleanup; |
| 279 |
|
} |
| 280 |
|
|
| 281 |
mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname))); |
mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname))); |
| 282 |
mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title))); |
mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title))); |
| 283 |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
| 284 |
|
|
| 285 |
|
free(content); |
| 286 |
|
content = NULL; |
| 287 |
|
|
| 288 |
// Add content |
// Add content |
| 289 |
snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
| 290 |
|
if (sql_content == NULL) |
| 291 |
|
{ |
| 292 |
|
log_error("malloc(sql_content) error: OOM\n"); |
| 293 |
|
ret = -1; |
| 294 |
|
goto cleanup; |
| 295 |
|
} |
| 296 |
|
|
| 297 |
|
snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
| 298 |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
| 299 |
content_f); |
content_f); |
| 300 |
|
|
| 301 |
if (mysql_query(db, sql) != 0) |
free(content_f); |
| 302 |
|
content_f = NULL; |
| 303 |
|
|
| 304 |
|
if (mysql_query(db, sql_content) != 0) |
| 305 |
{ |
{ |
| 306 |
log_error("Add article content error: %s\n", mysql_error(db)); |
log_error("Add article content error: %s\n", mysql_error(db)); |
| 307 |
ret = -1; |
ret = -1; |
| 310 |
|
|
| 311 |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
| 312 |
|
|
| 313 |
|
free(sql_content); |
| 314 |
|
sql_content = NULL; |
| 315 |
|
|
| 316 |
// Add article |
// Add article |
| 317 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 318 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 430 |
return 0; |
return 0; |
| 431 |
} |
} |
| 432 |
|
|
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) |
|
|
{ |
|
|
clearscr(); |
|
|
moveto(1, 1); |
|
|
prints("您没有权限在本版块发表文章\n"); |
|
|
press_any_key(); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
| 433 |
db = db_open(); |
db = db_open(); |
| 434 |
if (db == NULL) |
if (db == NULL) |
| 435 |
{ |
{ |
| 436 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 437 |
return -1; |
ret = -1; |
| 438 |
|
goto cleanup; |
| 439 |
} |
} |
| 440 |
|
|
| 441 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 447 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 448 |
{ |
{ |
| 449 |
log_error("Query article content error: %s\n", mysql_error(db)); |
log_error("Query article content error: %s\n", mysql_error(db)); |
| 450 |
ret = -2; |
ret = -1; |
| 451 |
goto cleanup; |
goto cleanup; |
| 452 |
} |
} |
| 453 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 454 |
{ |
{ |
| 455 |
log_error("Get article content data failed\n"); |
log_error("Get article content data failed\n"); |
| 456 |
ret = -2; |
ret = -1; |
| 457 |
goto cleanup; |
goto cleanup; |
| 458 |
} |
} |
| 459 |
|
|
| 460 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 461 |
{ |
{ |
| 462 |
p_editor_data = editor_data_load(row[1]); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 463 |
|
if (content == NULL) |
| 464 |
|
{ |
| 465 |
|
log_error("malloc(content) error: OOM\n"); |
| 466 |
|
ret = -1; |
| 467 |
|
goto cleanup; |
| 468 |
|
} |
| 469 |
|
|
| 470 |
|
strncpy(content, row[1], ARTICLE_CONTENT_MAX_LEN - 1); |
| 471 |
|
content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; |
| 472 |
|
|
| 473 |
|
// Remove control sequence |
| 474 |
|
len_content = ctrl_seq_filter(content); |
| 475 |
|
|
| 476 |
|
p_editor_data = editor_data_load(content); |
| 477 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 478 |
{ |
{ |
| 479 |
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])); |
| 480 |
ret = -3; |
ret = -1; |
| 481 |
goto cleanup; |
goto cleanup; |
| 482 |
} |
} |
| 483 |
|
|
| 484 |
|
free(content); |
| 485 |
|
content = NULL; |
| 486 |
} |
} |
| 487 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 488 |
rs = NULL; |
rs = NULL; |
| 536 |
if (len_content < 0) |
if (len_content < 0) |
| 537 |
{ |
{ |
| 538 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 539 |
ret = -2; |
ret = -1; |
| 540 |
goto cleanup; |
goto cleanup; |
| 541 |
} |
} |
| 542 |
|
|
| 548 |
"\n--\n※ 作者已于 %s 修改本文※\n", |
"\n--\n※ 作者已于 %s 修改本文※\n", |
| 549 |
str_modify_dt); |
str_modify_dt); |
| 550 |
|
|
|
content_f = malloc((size_t)len_content * 2 + 1); |
|
|
if (content_f == NULL) |
|
|
{ |
|
|
log_error("malloc(content_f) error: OOM\n"); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
|
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
|
|
if (sql_content == NULL) |
|
|
{ |
|
|
log_error("malloc(sql_content) error: OOM\n"); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
| 551 |
db = db_open(); |
db = db_open(); |
| 552 |
if (db == NULL) |
if (db == NULL) |
| 553 |
{ |
{ |
| 572 |
} |
} |
| 573 |
|
|
| 574 |
// Secure SQL parameters |
// Secure SQL parameters |
| 575 |
|
content_f = malloc((size_t)len_content * 2 + 1); |
| 576 |
|
if (content_f == NULL) |
| 577 |
|
{ |
| 578 |
|
log_error("malloc(content_f) error: OOM\n"); |
| 579 |
|
ret = -1; |
| 580 |
|
goto cleanup; |
| 581 |
|
} |
| 582 |
|
|
| 583 |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
| 584 |
|
|
| 585 |
|
free(content); |
| 586 |
|
content = NULL; |
| 587 |
|
|
| 588 |
// Add content |
// Add content |
| 589 |
snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
| 590 |
|
if (sql_content == NULL) |
| 591 |
|
{ |
| 592 |
|
log_error("malloc(sql_content) error: OOM\n"); |
| 593 |
|
ret = -1; |
| 594 |
|
goto cleanup; |
| 595 |
|
} |
| 596 |
|
|
| 597 |
|
snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
| 598 |
"INSERT INTO bbs_content(AID, content) values(%d, '%s')", |
"INSERT INTO bbs_content(AID, content) values(%d, '%s')", |
| 599 |
p_article->aid, content_f); |
p_article->aid, content_f); |
| 600 |
|
|
| 601 |
if (mysql_query(db, sql) != 0) |
free(content_f); |
| 602 |
|
content_f = NULL; |
| 603 |
|
|
| 604 |
|
if (mysql_query(db, sql_content) != 0) |
| 605 |
{ |
{ |
| 606 |
log_error("Add article content error: %s\n", mysql_error(db)); |
log_error("Add article content error: %s\n", mysql_error(db)); |
| 607 |
ret = -1; |
ret = -1; |
| 610 |
|
|
| 611 |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
| 612 |
|
|
| 613 |
|
free(sql_content); |
| 614 |
|
sql_content = NULL; |
| 615 |
|
|
| 616 |
// Update article |
// Update article |
| 617 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 618 |
"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 |
| 619 |
p_article_new->cid, len_content, p_article->aid); |
p_article_new->cid, len_content, p_article->aid); |
| 620 |
|
|
| 621 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 660 |
ret = 1; // Success |
ret = 1; // Success |
| 661 |
|
|
| 662 |
cleanup: |
cleanup: |
| 663 |
|
mysql_free_result(rs); |
| 664 |
mysql_close(db); |
mysql_close(db); |
| 665 |
|
|
| 666 |
// Cleanup buffers |
// Cleanup buffers |
| 697 |
long quote_content_lines; |
long quote_content_lines; |
| 698 |
long i; |
long i; |
| 699 |
long ret = 0; |
long ret = 0; |
| 700 |
|
int topic_locked = 0; |
| 701 |
|
|
| 702 |
if (p_section == NULL || p_article == NULL) |
if (p_section == NULL || p_article == NULL) |
| 703 |
{ |
{ |
| 714 |
return 0; |
return 0; |
| 715 |
} |
} |
| 716 |
|
|
|
if (p_article->lock) // Reply is not allowed |
|
|
{ |
|
|
clearscr(); |
|
|
moveto(1, 1); |
|
|
prints("该文章谢绝回复"); |
|
|
press_any_key(); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
| 717 |
p_article_new->title[0] = '\0'; |
p_article_new->title[0] = '\0'; |
| 718 |
snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); |
snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); |
| 719 |
len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len); |
len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len); |
| 723 |
if (db == NULL) |
if (db == NULL) |
| 724 |
{ |
{ |
| 725 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 726 |
return -1; |
ret = -1; |
| 727 |
|
goto cleanup; |
| 728 |
|
} |
| 729 |
|
|
| 730 |
|
snprintf(sql, sizeof(sql), |
| 731 |
|
"SELECT `lock` FROM bbs WHERE AID = %d", |
| 732 |
|
(p_article->tid == 0 ? p_article->aid : p_article->tid)); |
| 733 |
|
|
| 734 |
|
if (mysql_query(db, sql) != 0) |
| 735 |
|
{ |
| 736 |
|
log_error("Query article status error: %s\n", mysql_error(db)); |
| 737 |
|
ret = -1; |
| 738 |
|
goto cleanup; |
| 739 |
|
} |
| 740 |
|
if ((rs = mysql_store_result(db)) == NULL) |
| 741 |
|
{ |
| 742 |
|
log_error("Get article status data failed\n"); |
| 743 |
|
ret = -1; |
| 744 |
|
goto cleanup; |
| 745 |
|
} |
| 746 |
|
|
| 747 |
|
if ((row = mysql_fetch_row(rs))) |
| 748 |
|
{ |
| 749 |
|
if (atoi(row[0]) != 0) |
| 750 |
|
{ |
| 751 |
|
topic_locked = 1; |
| 752 |
|
} |
| 753 |
|
} |
| 754 |
|
mysql_free_result(rs); |
| 755 |
|
rs = NULL; |
| 756 |
|
|
| 757 |
|
if (topic_locked) // Reply is not allowed |
| 758 |
|
{ |
| 759 |
|
clearscr(); |
| 760 |
|
moveto(1, 1); |
| 761 |
|
prints("该主题谢绝回复"); |
| 762 |
|
press_any_key(); |
| 763 |
|
|
| 764 |
|
goto cleanup; |
| 765 |
} |
} |
| 766 |
|
|
| 767 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 773 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 774 |
{ |
{ |
| 775 |
log_error("Query article content error: %s\n", mysql_error(db)); |
log_error("Query article content error: %s\n", mysql_error(db)); |
| 776 |
return -2; |
ret = -1; |
| 777 |
|
goto cleanup; |
| 778 |
} |
} |
| 779 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 780 |
{ |
{ |
| 781 |
log_error("Get article content data failed\n"); |
log_error("Get article content data failed\n"); |
| 782 |
return -2; |
ret = -1; |
| 783 |
|
goto cleanup; |
| 784 |
} |
} |
| 785 |
|
|
| 786 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 834 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 835 |
{ |
{ |
| 836 |
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])); |
| 837 |
ret = -3; |
ret = -1; |
| 838 |
goto cleanup; |
goto cleanup; |
| 839 |
} |
} |
| 840 |
|
|
| 969 |
if (len_content < 0) |
if (len_content < 0) |
| 970 |
{ |
{ |
| 971 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 972 |
ret = -2; |
ret = -1; |
| 973 |
goto cleanup; |
goto cleanup; |
| 974 |
} |
} |
| 975 |
|
|
| 1010 |
rs = NULL; |
rs = NULL; |
| 1011 |
} |
} |
| 1012 |
|
|
|
content_f = malloc((size_t)len_content * 2 + 1); |
|
|
if (content_f == NULL) |
|
|
{ |
|
|
log_error("malloc(content_f) error: OOM\n"); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
|
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
|
|
if (sql_content == NULL) |
|
|
{ |
|
|
log_error("malloc(sql_content) error: OOM\n"); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
| 1013 |
// Begin transaction |
// Begin transaction |
| 1014 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 1015 |
{ |
{ |
| 1026 |
} |
} |
| 1027 |
|
|
| 1028 |
// Secure SQL parameters |
// Secure SQL parameters |
| 1029 |
|
content_f = malloc((size_t)len_content * 2 + 1); |
| 1030 |
|
if (content_f == NULL) |
| 1031 |
|
{ |
| 1032 |
|
log_error("malloc(content_f) error: OOM\n"); |
| 1033 |
|
ret = -1; |
| 1034 |
|
goto cleanup; |
| 1035 |
|
} |
| 1036 |
|
|
| 1037 |
mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname))); |
mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname))); |
| 1038 |
mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title))); |
mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title))); |
| 1039 |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
| 1040 |
|
|
| 1041 |
|
free(content); |
| 1042 |
|
content = NULL; |
| 1043 |
|
|
| 1044 |
// Add content |
// Add content |
| 1045 |
snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
| 1046 |
|
if (sql_content == NULL) |
| 1047 |
|
{ |
| 1048 |
|
log_error("malloc(sql_content) error: OOM\n"); |
| 1049 |
|
ret = -1; |
| 1050 |
|
goto cleanup; |
| 1051 |
|
} |
| 1052 |
|
|
| 1053 |
|
snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
| 1054 |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
| 1055 |
content_f); |
content_f); |
| 1056 |
|
|
| 1057 |
if (mysql_query(db, sql) != 0) |
free(content_f); |
| 1058 |
|
content_f = NULL; |
| 1059 |
|
|
| 1060 |
|
if (mysql_query(db, sql_content) != 0) |
| 1061 |
{ |
{ |
| 1062 |
log_error("Add article content error: %s\n", mysql_error(db)); |
log_error("Add article content error: %s\n", mysql_error(db)); |
| 1063 |
ret = -1; |
ret = -1; |
| 1066 |
|
|
| 1067 |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
| 1068 |
|
|
| 1069 |
|
free(sql_content); |
| 1070 |
|
sql_content = NULL; |
| 1071 |
|
|
| 1072 |
// Add article |
// Add article |
| 1073 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 1074 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |