| 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, " |
| 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 |
| 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, " |