| 16 |
|
|
| 17 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 18 |
#include "article_cache.h" |
#include "article_cache.h" |
| 19 |
|
#include "bbs.h" |
| 20 |
#include "log.h" |
#include "log.h" |
| 21 |
#include "database.h" |
#include "database.h" |
| 22 |
#include "menu.h" |
#include "menu.h" |
| 25 |
#include <errno.h> |
#include <errno.h> |
| 26 |
#include <signal.h> |
#include <signal.h> |
| 27 |
#include <stdlib.h> |
#include <stdlib.h> |
| 28 |
|
#include <string.h> |
| 29 |
#include <strings.h> |
#include <strings.h> |
| 30 |
#include <unistd.h> |
#include <unistd.h> |
| 31 |
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
|
#include <string.h> |
|
|
|
|
|
#define SECTION_LIST_LOAD_INTERVAL 10 // second |
|
|
|
|
| 32 |
int section_list_loader_pid; |
int section_list_loader_pid; |
| 33 |
int last_article_op_log_mid; |
int last_article_op_log_mid; |
| 34 |
|
|
| 35 |
int load_section_config_from_db(void) |
int load_section_config_from_db(void) |
| 36 |
{ |
{ |
| 37 |
MYSQL *db; |
MYSQL *db = NULL; |
| 38 |
MYSQL_RES *rs, *rs2; |
MYSQL_RES *rs = NULL, *rs2 = NULL; |
| 39 |
MYSQL_ROW row, row2; |
MYSQL_ROW row, row2; |
| 40 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 41 |
int32_t sid; |
int32_t sid; |
| 42 |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
| 43 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 44 |
int ret; |
int ret = 0; |
| 45 |
|
|
| 46 |
db = db_open(); |
db = db_open(); |
| 47 |
if (db == NULL) |
if (db == NULL) |
| 48 |
{ |
{ |
| 49 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 50 |
return -2; |
ret = -1; |
| 51 |
|
goto cleanup; |
| 52 |
} |
} |
| 53 |
|
|
| 54 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 60 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 61 |
{ |
{ |
| 62 |
log_error("Query section_list error: %s\n", mysql_error(db)); |
log_error("Query section_list error: %s\n", mysql_error(db)); |
| 63 |
return -3; |
ret = -2; |
| 64 |
|
goto cleanup; |
| 65 |
} |
} |
| 66 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 67 |
{ |
{ |
| 68 |
log_error("Get section_list data failed\n"); |
log_error("Get section_list data failed\n"); |
| 69 |
return -3; |
ret = -2; |
| 70 |
|
goto cleanup; |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
ret = 0; |
ret = 0; |
| 103 |
strncat(master_list, " ", sizeof(master_list) - 1 - strnlen(master_list, sizeof(master_list))); |
strncat(master_list, " ", sizeof(master_list) - 1 - strnlen(master_list, sizeof(master_list))); |
| 104 |
} |
} |
| 105 |
mysql_free_result(rs2); |
mysql_free_result(rs2); |
| 106 |
|
rs2 = NULL; |
| 107 |
|
|
| 108 |
p_section = section_list_find_by_sid(sid); |
p_section = section_list_find_by_sid(sid); |
| 109 |
|
|
| 133 |
break; |
break; |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1); |
strncpy(p_section->sname, row[0], sizeof(p_section->sname) - 1); |
| 137 |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 138 |
strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1); |
strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1); |
| 139 |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
| 153 |
break; |
break; |
| 154 |
} |
} |
| 155 |
} |
} |
|
mysql_free_result(rs); |
|
| 156 |
|
|
| 157 |
|
cleanup: |
| 158 |
|
mysql_free_result(rs); |
| 159 |
mysql_close(db); |
mysql_close(db); |
| 160 |
|
|
| 161 |
return ret; |
return ret; |
| 163 |
|
|
| 164 |
int append_articles_from_db(int32_t start_aid, int global_lock, int article_count_limit) |
int append_articles_from_db(int32_t start_aid, int global_lock, int article_count_limit) |
| 165 |
{ |
{ |
| 166 |
MYSQL *db; |
MYSQL *db = NULL; |
| 167 |
MYSQL_RES *rs; |
MYSQL_RES *rs = NULL; |
| 168 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 169 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 170 |
ARTICLE article; |
ARTICLE article; |
| 171 |
ARTICLE *p_topic; |
ARTICLE *p_topic; |
| 172 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 173 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 174 |
|
char sub_ip[IP_ADDR_LEN]; |
| 175 |
int article_count = 0; |
int article_count = 0; |
| 176 |
int ret = 0; |
int ret = 0; |
| 177 |
int i; |
int i; |
| 180 |
if (db == NULL) |
if (db == NULL) |
| 181 |
{ |
{ |
| 182 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 183 |
return -2; |
ret = -1; |
| 184 |
|
goto cleanup; |
| 185 |
} |
} |
| 186 |
|
|
| 187 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 188 |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
| 189 |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
| 190 |
"bbs_content.content " |
"sub_ip, bbs_content.content " |
| 191 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 192 |
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
| 193 |
start_aid, article_count_limit); |
start_aid, article_count_limit); |
| 195 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 196 |
{ |
{ |
| 197 |
log_error("Query article list error: %s\n", mysql_error(db)); |
log_error("Query article list error: %s\n", mysql_error(db)); |
| 198 |
return -3; |
ret = -2; |
| 199 |
|
goto cleanup; |
| 200 |
} |
} |
| 201 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 202 |
{ |
{ |
| 203 |
log_error("Get article list data failed\n"); |
log_error("Get article list data failed\n"); |
| 204 |
return -3; |
ret = -2; |
| 205 |
|
goto cleanup; |
| 206 |
} |
} |
| 207 |
|
|
| 208 |
// acquire global lock |
// acquire global lock |
| 209 |
if (global_lock) |
if (global_lock && (ret = section_list_rw_lock(NULL)) < 0) |
| 210 |
{ |
{ |
| 211 |
if ((ret = section_list_rw_lock(NULL)) < 0) |
log_error("section_list_rw_lock(sid = 0) error\n"); |
| 212 |
{ |
goto cleanup; |
|
log_error("section_list_rw_lock(sid = 0) error\n"); |
|
|
goto cleanup; |
|
|
} |
|
| 213 |
} |
} |
| 214 |
|
|
| 215 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |
| 216 |
{ |
{ |
| 217 |
bzero(&article, sizeof(ARTICLE)); |
memset(&article, 0, sizeof(ARTICLE)); |
| 218 |
|
|
| 219 |
// copy data of article |
// copy data of article |
| 220 |
i = 0; |
i = 0; |
| 239 |
|
|
| 240 |
article.sub_dt = atol(row[i++]); |
article.sub_dt = atol(row[i++]); |
| 241 |
|
|
| 242 |
|
strncpy(sub_ip, row[i++], sizeof(sub_ip) - 1); |
| 243 |
|
sub_ip[sizeof(sub_ip) - 1] = '\0'; |
| 244 |
|
ip_mask(sub_ip, 1, '*'); |
| 245 |
|
|
| 246 |
// release lock of last section if different from current one |
// release lock of last section if different from current one |
| 247 |
if (!global_lock && article.sid != last_sid && last_sid != 0) |
if (!global_lock && article.sid != last_sid && last_sid != 0) |
| 248 |
{ |
{ |
| 295 |
|
|
| 296 |
article_count++; |
article_count++; |
| 297 |
|
|
| 298 |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, p_section, row[i++], 0) < 0) |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, p_section, row[i++], sub_ip, 0) < 0) |
| 299 |
{ |
{ |
| 300 |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid); |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid); |
| 301 |
ret = -4; |
ret = -4; |
| 313 |
} |
} |
| 314 |
|
|
| 315 |
// release global lock |
// release global lock |
| 316 |
if (global_lock) |
if (global_lock && (ret = section_list_rw_unlock(NULL)) < 0) |
| 317 |
{ |
{ |
| 318 |
if ((ret = section_list_rw_unlock(NULL)) < 0) |
log_error("section_list_rw_unlock(sid=0) error\n"); |
|
{ |
|
|
log_error("section_list_rw_unlock(sid=0) error\n"); |
|
|
} |
|
| 319 |
} |
} |
| 320 |
|
|
| 321 |
cleanup: |
cleanup: |
| 322 |
mysql_free_result(rs); |
mysql_free_result(rs); |
|
|
|
| 323 |
mysql_close(db); |
mysql_close(db); |
| 324 |
|
|
| 325 |
return (ret < 0 ? ret : article_count); |
return (ret < 0 ? ret : article_count); |
| 327 |
|
|
| 328 |
int set_last_article_op_log_from_db(void) |
int set_last_article_op_log_from_db(void) |
| 329 |
{ |
{ |
| 330 |
MYSQL *db; |
MYSQL *db = NULL; |
| 331 |
MYSQL_RES *rs; |
MYSQL_RES *rs = NULL; |
| 332 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 333 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 334 |
|
int ret = 0; |
| 335 |
|
|
| 336 |
db = db_open(); |
db = db_open(); |
| 337 |
if (db == NULL) |
if (db == NULL) |
| 338 |
{ |
{ |
| 339 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 340 |
return -1; |
ret = -1; |
| 341 |
|
goto cleanup; |
| 342 |
} |
} |
| 343 |
|
|
| 344 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 347 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 348 |
{ |
{ |
| 349 |
log_error("Query article op error: %s\n", mysql_error(db)); |
log_error("Query article op error: %s\n", mysql_error(db)); |
| 350 |
return -2; |
ret = -2; |
| 351 |
|
goto cleanup; |
| 352 |
} |
} |
| 353 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 354 |
{ |
{ |
| 355 |
log_error("Get article op data failed\n"); |
log_error("Get article op data failed\n"); |
| 356 |
return -2; |
ret = -2; |
| 357 |
|
goto cleanup; |
| 358 |
} |
} |
| 359 |
|
|
| 360 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 362 |
last_article_op_log_mid = atoi(row[0]); |
last_article_op_log_mid = atoi(row[0]); |
| 363 |
} |
} |
| 364 |
|
|
| 365 |
|
cleanup: |
| 366 |
mysql_free_result(rs); |
mysql_free_result(rs); |
|
|
|
| 367 |
mysql_close(db); |
mysql_close(db); |
| 368 |
|
|
| 369 |
return last_article_op_log_mid; |
return (ret < 0 ? ret : last_article_op_log_mid); |
| 370 |
} |
} |
| 371 |
|
|
| 372 |
int apply_article_op_log_from_db(int op_count_limit) |
int apply_article_op_log_from_db(int op_count_limit) |
| 373 |
{ |
{ |
| 374 |
MYSQL *db; |
MYSQL *db = NULL; |
| 375 |
MYSQL_RES *rs, *rs2; |
MYSQL_RES *rs = NULL, *rs2 = NULL; |
| 376 |
MYSQL_ROW row, row2; |
MYSQL_ROW row, row2; |
| 377 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 378 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 379 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 380 |
SECTION_LIST *p_section_dest; |
SECTION_LIST *p_section_dest; |
| 381 |
|
char sub_ip[IP_ADDR_LEN]; |
| 382 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 383 |
int32_t sid_dest; |
int32_t sid_dest; |
| 384 |
int op_count = 0; |
int op_count = 0; |
| 388 |
if (db == NULL) |
if (db == NULL) |
| 389 |
{ |
{ |
| 390 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 391 |
return -3; |
ret = -1; |
| 392 |
|
goto cleanup; |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 401 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 402 |
{ |
{ |
| 403 |
log_error("Query article log error: %s\n", mysql_error(db)); |
log_error("Query article log error: %s\n", mysql_error(db)); |
| 404 |
return -3; |
ret = -2; |
| 405 |
|
goto cleanup; |
| 406 |
} |
} |
| 407 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 408 |
{ |
{ |
| 409 |
log_error("Get article log data failed\n"); |
log_error("Get article log data failed\n"); |
| 410 |
return -3; |
ret = -2; |
| 411 |
|
goto cleanup; |
| 412 |
} |
} |
| 413 |
|
|
| 414 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |
| 456 |
break; |
break; |
| 457 |
case 'D': // Delete article |
case 'D': // Delete article |
| 458 |
case 'X': // Delete article by Admin |
case 'X': // Delete article by Admin |
| 459 |
p_article->visible = 0; |
if (section_list_set_article_visible(p_section, atoi(row[1]), 0) < 0) |
|
if (p_article->tid == 0) |
|
| 460 |
{ |
{ |
| 461 |
// Set articles in the topic to be invisible |
log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=0) error\n", p_section->sid, atoi(row[1])); |
| 462 |
do |
} |
| 463 |
{ |
if (section_list_calculate_page(p_section, atoi(row[1])) < 0) |
| 464 |
p_article = p_article->p_topic_next; |
{ |
| 465 |
p_article->visible = 0; |
log_error("section_list_calculate_page(aid=%d) error\n", atoi(row[1])); |
|
} while (p_article->tid != 0); |
|
| 466 |
} |
} |
| 467 |
break; |
break; |
| 468 |
case 'S': // Restore article |
case 'S': // Restore article |
| 469 |
p_article->visible = 1; |
if (section_list_set_article_visible(p_section, atoi(row[1]), 1) < 0) |
| 470 |
|
{ |
| 471 |
|
log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=1) error\n", p_section->sid, atoi(row[1])); |
| 472 |
|
} |
| 473 |
|
if (section_list_calculate_page(p_section, atoi(row[1])) < 0) |
| 474 |
|
{ |
| 475 |
|
log_error("section_list_calculate_page(aid=%d) error\n", atoi(row[1])); |
| 476 |
|
} |
| 477 |
break; |
break; |
| 478 |
case 'L': // Lock article |
case 'L': // Lock article |
| 479 |
p_article->lock = 1; |
p_article->lock = 1; |
| 483 |
break; |
break; |
| 484 |
case 'M': // Modify article |
case 'M': // Modify article |
| 485 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 486 |
"SELECT bbs.CID, bbs_content.content " |
"SELECT bbs.CID, sub_ip, bbs_content.content " |
| 487 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 488 |
"WHERE bbs.AID = %d", |
"WHERE bbs.AID = %d", |
| 489 |
p_article->aid); |
p_article->aid); |
| 504 |
{ |
{ |
| 505 |
p_article->cid = atoi(row2[0]); |
p_article->cid = atoi(row2[0]); |
| 506 |
|
|
| 507 |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[1], 0) < 0) |
strncpy(sub_ip, row2[1], sizeof(sub_ip) - 1); |
| 508 |
|
sub_ip[sizeof(sub_ip) - 1] = '\0'; |
| 509 |
|
ip_mask(sub_ip, 1, '*'); |
| 510 |
|
|
| 511 |
|
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[2], sub_ip, 0) < 0) |
| 512 |
{ |
{ |
| 513 |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 514 |
ret = -4; |
ret = -4; |
| 520 |
ret = -4; |
ret = -4; |
| 521 |
} |
} |
| 522 |
mysql_free_result(rs2); |
mysql_free_result(rs2); |
| 523 |
|
rs2 = NULL; |
| 524 |
|
|
| 525 |
|
p_article->excerption = 0; // Set excerption = 0 implicitly in case of rare condition |
| 526 |
break; |
break; |
| 527 |
case 'T': // Move article |
case 'T': // Move article |
| 528 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 551 |
ret = -4; |
ret = -4; |
| 552 |
} |
} |
| 553 |
mysql_free_result(rs2); |
mysql_free_result(rs2); |
| 554 |
|
rs2 = NULL; |
| 555 |
|
|
| 556 |
if (sid_dest > 0 && sid_dest != p_article->sid) |
if (sid_dest > 0 && sid_dest != p_article->sid) |
| 557 |
{ |
{ |
| 621 |
} |
} |
| 622 |
} |
} |
| 623 |
|
|
| 624 |
|
cleanup: |
| 625 |
|
mysql_free_result(rs2); |
| 626 |
mysql_free_result(rs); |
mysql_free_result(rs); |
|
|
|
| 627 |
mysql_close(db); |
mysql_close(db); |
| 628 |
|
|
| 629 |
return (ret < 0 ? ret : op_count); |
return (ret < 0 ? ret : op_count); |
| 651 |
{ |
{ |
| 652 |
SYS_child_process_count++; |
SYS_child_process_count++; |
| 653 |
section_list_loader_pid = pid; |
section_list_loader_pid = pid; |
| 654 |
log_std("Section list loader process (%d) start\n", pid); |
log_common("Section list loader process (pid = %d) start\n", pid); |
| 655 |
return 0; |
return 0; |
| 656 |
} |
} |
| 657 |
else if (pid < 0) // Error |
else if (pid < 0) // Error |
| 682 |
} |
} |
| 683 |
else |
else |
| 684 |
{ |
{ |
| 685 |
log_error("Reload section config successfully\n"); |
log_common("Reload section config successfully\n"); |
| 686 |
} |
} |
| 687 |
} |
} |
| 688 |
|
|
| 707 |
load_count = article_block_article_count() - article_count; |
load_count = article_block_article_count() - article_count; |
| 708 |
if (load_count > 0) |
if (load_count > 0) |
| 709 |
{ |
{ |
| 710 |
log_std("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
log_common("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
| 711 |
} |
} |
| 712 |
|
|
| 713 |
if (SYS_section_list_reload) |
if (SYS_section_list_reload) |
| 733 |
|
|
| 734 |
if (last_article_op_log_mid > last_mid) |
if (last_article_op_log_mid > last_mid) |
| 735 |
{ |
{ |
| 736 |
log_std("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); |
log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); |
| 737 |
} |
} |
| 738 |
|
|
| 739 |
if (SYS_section_list_reload) |
if (SYS_section_list_reload) |
| 741 |
continue; |
continue; |
| 742 |
} |
} |
| 743 |
|
|
| 744 |
for (i = 0; i < SECTION_LIST_LOAD_INTERVAL && !SYS_server_exit && !SYS_section_list_reload; i++) |
for (i = 0; i < BBS_section_list_load_interval && !SYS_server_exit && !SYS_section_list_reload; i++) |
| 745 |
{ |
{ |
| 746 |
sleep(1); |
sleep(1); |
| 747 |
} |
} |
| 754 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 755 |
detach_trie_dict_shm(); |
detach_trie_dict_shm(); |
| 756 |
|
|
| 757 |
log_std("Section list loader process exit normally\n"); |
log_common("Section list loader process exit normally\n"); |
| 758 |
log_end(); |
log_end(); |
| 759 |
|
|
| 760 |
section_list_loader_pid = 0; |
section_list_loader_pid = 0; |
| 845 |
return ret; |
return ret; |
| 846 |
} |
} |
| 847 |
|
|
| 848 |
int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction, |
int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction, int step, |
| 849 |
int *p_page_id, int *p_offset, int *p_article_count) |
int *p_page_id, int *p_visible_offset, int *p_article_count) |
| 850 |
{ |
{ |
| 851 |
ARTICLE *p_article = NULL; |
const ARTICLE *p_article = NULL; |
| 852 |
ARTICLE *p_next; |
ARTICLE *p_tmp; |
| 853 |
int32_t aid = 0; |
int32_t aid = 0; |
| 854 |
|
int page_id = 0; |
| 855 |
|
int offset = 0; |
| 856 |
int ret = 0; |
int ret = 0; |
| 857 |
|
int i; |
| 858 |
|
|
| 859 |
if (p_section == NULL || p_article_cur == NULL || p_page_id == NULL || p_offset == NULL || p_article_count == NULL) |
if (p_section == NULL || p_article_cur == NULL || p_page_id == NULL || p_visible_offset == NULL || p_article_count == NULL) |
| 860 |
{ |
{ |
| 861 |
log_error("locate_article_in_section() NULL pointer error\n"); |
log_error("locate_article_in_section() NULL pointer error\n"); |
| 862 |
return -1; |
return -1; |
| 875 |
} |
} |
| 876 |
else if (direction == 1) |
else if (direction == 1) |
| 877 |
{ |
{ |
| 878 |
aid = p_article_cur->p_topic_next->aid; |
for (p_article = p_article_cur; step > 0 && p_article->p_topic_next->aid > p_article_cur->aid; p_article = p_article->p_topic_next) |
|
if (aid <= p_article_cur->aid) |
|
| 879 |
{ |
{ |
| 880 |
aid = 0; |
if (p_article->visible) |
| 881 |
|
{ |
| 882 |
|
step--; |
| 883 |
|
} |
| 884 |
} |
} |
| 885 |
|
|
| 886 |
|
aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0); |
| 887 |
} |
} |
| 888 |
else if (direction == -1) |
else if (direction == -1) |
| 889 |
{ |
{ |
| 890 |
aid = p_article_cur->p_topic_prior->aid; |
for (p_article = p_article_cur; step > 0 && p_article->p_topic_prior->aid < p_article_cur->aid; p_article = p_article->p_topic_prior) |
|
if (aid >= p_article_cur->aid) |
|
| 891 |
{ |
{ |
| 892 |
aid = 0; |
if (p_article->visible) |
| 893 |
|
{ |
| 894 |
|
step--; |
| 895 |
|
} |
| 896 |
} |
} |
| 897 |
|
|
| 898 |
|
aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0); |
| 899 |
} |
} |
| 900 |
|
|
| 901 |
|
p_article = NULL; |
| 902 |
|
|
| 903 |
if (aid > 0) |
if (aid > 0) |
| 904 |
{ |
{ |
| 905 |
p_article = section_list_find_article_with_offset(p_section, aid, p_page_id, p_offset, &p_next); |
p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp); |
| 906 |
if (p_article != NULL) |
if (p_article != NULL) |
| 907 |
{ |
{ |
| 908 |
*p_article_count = (*p_page_id == p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page); |
*p_article_count = (page_id == p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page); |
| 909 |
|
|
| 910 |
|
p_article = p_section->p_page_first_article[page_id]; |
| 911 |
|
for (i = 0; i < *p_article_count && p_article != NULL;) |
| 912 |
|
{ |
| 913 |
|
if (p_article->visible) |
| 914 |
|
{ |
| 915 |
|
if (p_article->aid == aid) |
| 916 |
|
{ |
| 917 |
|
*p_page_id = page_id; |
| 918 |
|
*p_visible_offset = i; |
| 919 |
|
break; |
| 920 |
|
} |
| 921 |
|
i++; |
| 922 |
|
if (i >= *p_article_count) |
| 923 |
|
{ |
| 924 |
|
log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id); |
| 925 |
|
p_article = NULL; |
| 926 |
|
break; |
| 927 |
|
} |
| 928 |
|
} |
| 929 |
|
p_article = p_article->p_next; |
| 930 |
|
} |
| 931 |
} |
} |
| 932 |
} |
} |
| 933 |
|
|