| 63 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error\n"); |
| 64 |
} |
} |
| 65 |
|
|
| 66 |
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) |
| 67 |
|
{ |
| 68 |
|
clearscr(); |
| 69 |
|
moveto(1, 1); |
| 70 |
|
prints("您没有权限在本版块发表文章\n"); |
| 71 |
|
press_any_key(); |
| 72 |
|
|
| 73 |
|
return 0; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
p_article_new->title[0] = '\0'; |
p_article_new->title[0] = '\0'; |
| 77 |
title_input[0] = '\0'; |
title_input[0] = '\0'; |
| 78 |
p_article_new->transship = 0; |
p_article_new->transship = 0; |
| 253 |
rs = NULL; |
rs = NULL; |
| 254 |
} |
} |
| 255 |
|
|
|
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; |
|
|
} |
|
|
|
|
| 256 |
// Begin transaction |
// Begin transaction |
| 257 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 258 |
{ |
{ |
| 269 |
} |
} |
| 270 |
|
|
| 271 |
// Secure SQL parameters |
// Secure SQL parameters |
| 272 |
|
content_f = malloc((size_t)len_content * 2 + 1); |
| 273 |
|
if (content_f == NULL) |
| 274 |
|
{ |
| 275 |
|
log_error("malloc(content_f) error: OOM\n"); |
| 276 |
|
ret = -1; |
| 277 |
|
goto cleanup; |
| 278 |
|
} |
| 279 |
|
|
| 280 |
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))); |
| 281 |
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))); |
| 282 |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
| 283 |
|
|
| 284 |
|
free(content); |
| 285 |
|
content = NULL; |
| 286 |
|
|
| 287 |
// Add content |
// Add content |
| 288 |
snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
| 289 |
|
if (sql_content == NULL) |
| 290 |
|
{ |
| 291 |
|
log_error("malloc(sql_content) error: OOM\n"); |
| 292 |
|
ret = -1; |
| 293 |
|
goto cleanup; |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
| 297 |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
| 298 |
content_f); |
content_f); |
| 299 |
|
|
| 300 |
if (mysql_query(db, sql) != 0) |
free(content_f); |
| 301 |
|
content_f = NULL; |
| 302 |
|
|
| 303 |
|
if (mysql_query(db, sql_content) != 0) |
| 304 |
{ |
{ |
| 305 |
log_error("Add article content error: %s\n", mysql_error(db)); |
log_error("Add article content error: %s\n", mysql_error(db)); |
| 306 |
ret = -1; |
ret = -1; |
| 309 |
|
|
| 310 |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
| 311 |
|
|
| 312 |
|
free(sql_content); |
| 313 |
|
sql_content = NULL; |
| 314 |
|
|
| 315 |
// Add article |
// Add article |
| 316 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 317 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 429 |
return 0; |
return 0; |
| 430 |
} |
} |
| 431 |
|
|
| 432 |
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) |
| 433 |
|
{ |
| 434 |
|
clearscr(); |
| 435 |
|
moveto(1, 1); |
| 436 |
|
prints("您没有权限在本版块发表文章\n"); |
| 437 |
|
press_any_key(); |
| 438 |
|
|
| 439 |
|
return 0; |
| 440 |
|
} |
| 441 |
|
|
| 442 |
db = db_open(); |
db = db_open(); |
| 443 |
if (db == NULL) |
if (db == NULL) |
| 444 |
{ |
{ |
| 467 |
|
|
| 468 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 469 |
{ |
{ |
| 470 |
p_editor_data = editor_data_load(row[1]); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 471 |
|
if (content == NULL) |
| 472 |
|
{ |
| 473 |
|
log_error("malloc(content) error: OOM\n"); |
| 474 |
|
ret = -1; |
| 475 |
|
goto cleanup; |
| 476 |
|
} |
| 477 |
|
|
| 478 |
|
strncpy(content, row[1], ARTICLE_CONTENT_MAX_LEN - 1); |
| 479 |
|
content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; |
| 480 |
|
|
| 481 |
|
// Remove control sequence |
| 482 |
|
len_content = ctrl_seq_filter(content); |
| 483 |
|
|
| 484 |
|
p_editor_data = editor_data_load(content); |
| 485 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 486 |
{ |
{ |
| 487 |
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])); |
| 488 |
ret = -3; |
ret = -3; |
| 489 |
goto cleanup; |
goto cleanup; |
| 490 |
} |
} |
| 491 |
|
|
| 492 |
|
free(content); |
| 493 |
|
content = NULL; |
| 494 |
} |
} |
| 495 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 496 |
rs = NULL; |
rs = NULL; |
| 556 |
"\n--\n※ 作者已于 %s 修改本文※\n", |
"\n--\n※ 作者已于 %s 修改本文※\n", |
| 557 |
str_modify_dt); |
str_modify_dt); |
| 558 |
|
|
|
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; |
|
|
} |
|
|
|
|
| 559 |
db = db_open(); |
db = db_open(); |
| 560 |
if (db == NULL) |
if (db == NULL) |
| 561 |
{ |
{ |
| 580 |
} |
} |
| 581 |
|
|
| 582 |
// Secure SQL parameters |
// Secure SQL parameters |
| 583 |
|
content_f = malloc((size_t)len_content * 2 + 1); |
| 584 |
|
if (content_f == NULL) |
| 585 |
|
{ |
| 586 |
|
log_error("malloc(content_f) error: OOM\n"); |
| 587 |
|
ret = -1; |
| 588 |
|
goto cleanup; |
| 589 |
|
} |
| 590 |
|
|
| 591 |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
| 592 |
|
|
| 593 |
|
free(content); |
| 594 |
|
content = NULL; |
| 595 |
|
|
| 596 |
// Add content |
// Add content |
| 597 |
snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
| 598 |
|
if (sql_content == NULL) |
| 599 |
|
{ |
| 600 |
|
log_error("malloc(sql_content) error: OOM\n"); |
| 601 |
|
ret = -1; |
| 602 |
|
goto cleanup; |
| 603 |
|
} |
| 604 |
|
|
| 605 |
|
snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
| 606 |
"INSERT INTO bbs_content(AID, content) values(%d, '%s')", |
"INSERT INTO bbs_content(AID, content) values(%d, '%s')", |
| 607 |
p_article->aid, content_f); |
p_article->aid, content_f); |
| 608 |
|
|
| 609 |
if (mysql_query(db, sql) != 0) |
free(content_f); |
| 610 |
|
content_f = NULL; |
| 611 |
|
|
| 612 |
|
if (mysql_query(db, sql_content) != 0) |
| 613 |
{ |
{ |
| 614 |
log_error("Add article content error: %s\n", mysql_error(db)); |
log_error("Add article content error: %s\n", mysql_error(db)); |
| 615 |
ret = -1; |
ret = -1; |
| 618 |
|
|
| 619 |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
| 620 |
|
|
| 621 |
|
free(sql_content); |
| 622 |
|
sql_content = NULL; |
| 623 |
|
|
| 624 |
// Update article |
// Update article |
| 625 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 626 |
"UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d", |
"UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d", |
| 668 |
ret = 1; // Success |
ret = 1; // Success |
| 669 |
|
|
| 670 |
cleanup: |
cleanup: |
| 671 |
|
mysql_free_result(rs); |
| 672 |
mysql_close(db); |
mysql_close(db); |
| 673 |
|
|
| 674 |
// Cleanup buffers |
// Cleanup buffers |
| 711 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error\n"); |
| 712 |
} |
} |
| 713 |
|
|
| 714 |
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) |
| 715 |
|
{ |
| 716 |
|
clearscr(); |
| 717 |
|
moveto(1, 1); |
| 718 |
|
prints("您没有权限在本版块发表文章\n"); |
| 719 |
|
press_any_key(); |
| 720 |
|
|
| 721 |
|
return 0; |
| 722 |
|
} |
| 723 |
|
|
| 724 |
if (p_article->lock) // Reply is not allowed |
if (p_article->lock) // Reply is not allowed |
| 725 |
{ |
{ |
| 726 |
clearscr(); |
clearscr(); |
| 987 |
rs = NULL; |
rs = NULL; |
| 988 |
} |
} |
| 989 |
|
|
|
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; |
|
|
} |
|
|
|
|
| 990 |
// Begin transaction |
// Begin transaction |
| 991 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 992 |
{ |
{ |
| 1003 |
} |
} |
| 1004 |
|
|
| 1005 |
// Secure SQL parameters |
// Secure SQL parameters |
| 1006 |
|
content_f = malloc((size_t)len_content * 2 + 1); |
| 1007 |
|
if (content_f == NULL) |
| 1008 |
|
{ |
| 1009 |
|
log_error("malloc(content_f) error: OOM\n"); |
| 1010 |
|
ret = -1; |
| 1011 |
|
goto cleanup; |
| 1012 |
|
} |
| 1013 |
|
|
| 1014 |
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))); |
| 1015 |
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))); |
| 1016 |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
mysql_real_escape_string(db, content_f, content, (unsigned long)len_content); |
| 1017 |
|
|
| 1018 |
|
free(content); |
| 1019 |
|
content = NULL; |
| 1020 |
|
|
| 1021 |
// Add content |
// Add content |
| 1022 |
snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); |
| 1023 |
|
if (sql_content == NULL) |
| 1024 |
|
{ |
| 1025 |
|
log_error("malloc(sql_content) error: OOM\n"); |
| 1026 |
|
ret = -1; |
| 1027 |
|
goto cleanup; |
| 1028 |
|
} |
| 1029 |
|
|
| 1030 |
|
snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1, |
| 1031 |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
"INSERT INTO bbs_content(AID, content) values(0, '%s')", |
| 1032 |
content_f); |
content_f); |
| 1033 |
|
|
| 1034 |
if (mysql_query(db, sql) != 0) |
free(content_f); |
| 1035 |
|
content_f = NULL; |
| 1036 |
|
|
| 1037 |
|
if (mysql_query(db, sql_content) != 0) |
| 1038 |
{ |
{ |
| 1039 |
log_error("Add article content error: %s\n", mysql_error(db)); |
log_error("Add article content error: %s\n", mysql_error(db)); |
| 1040 |
ret = -1; |
ret = -1; |
| 1043 |
|
|
| 1044 |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
p_article_new->cid = (int32_t)mysql_insert_id(db); |
| 1045 |
|
|
| 1046 |
|
free(sql_content); |
| 1047 |
|
sql_content = NULL; |
| 1048 |
|
|
| 1049 |
// Add article |
// Add article |
| 1050 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 1051 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 1052 |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
| 1053 |
"VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', 1, %d, NOW(), 1, %ld)", |
"VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', 1, %d, NOW(), 1, %ld)", |
| 1054 |
p_section->sid, p_article->aid, BBS_priv.uid, BBS_username, nickname_f, title_f, |
p_section->sid, (p_article->tid == 0 ? p_article->aid : p_article->tid), |
| 1055 |
|
BBS_priv.uid, BBS_username, nickname_f, title_f, |
| 1056 |
p_article_new->cid, hostaddr_client, BBS_user_exp, len_content); |
p_article_new->cid, hostaddr_client, BBS_user_exp, len_content); |
| 1057 |
|
|
| 1058 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 1068 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 1069 |
"UPDATE bbs SET reply_count = reply_count + 1, " |
"UPDATE bbs SET reply_count = reply_count + 1, " |
| 1070 |
"last_reply_dt = NOW(), last_reply_UID=%d, last_reply_username = '%s', " |
"last_reply_dt = NOW(), last_reply_UID=%d, last_reply_username = '%s', " |
| 1071 |
"last_reply_nickname = '%s' WHERE Aid = %d", |
"last_reply_nickname = '%s' WHERE AID = %d", |
| 1072 |
BBS_priv.uid, BBS_username, nickname_f, p_article->aid); |
BBS_priv.uid, BBS_username, nickname_f, |
| 1073 |
|
(p_article->tid == 0 ? p_article->aid : p_article->tid)); |
| 1074 |
|
|
| 1075 |
|
if (mysql_query(db, sql) != 0) |
| 1076 |
|
{ |
| 1077 |
|
log_error("Update topic article error: %s\n", mysql_error(db)); |
| 1078 |
|
ret = -1; |
| 1079 |
|
goto cleanup; |
| 1080 |
|
} |
| 1081 |
|
|
| 1082 |
// Link content to article |
// Link content to article |
| 1083 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |