| 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" |
| 31 |
#define _POSIX_C_SOURCE 200809L |
#define _POSIX_C_SOURCE 200809L |
| 32 |
#include <string.h> |
#include <string.h> |
| 33 |
|
|
|
#define SECTION_LIST_LOAD_INTERVAL 10 // second |
|
|
|
|
| 34 |
int section_list_loader_pid; |
int section_list_loader_pid; |
| 35 |
int last_article_op_log_mid; |
int last_article_op_log_mid; |
| 36 |
|
|
| 168 |
ARTICLE *p_topic; |
ARTICLE *p_topic; |
| 169 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 170 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 171 |
|
char sub_ip[IP_ADDR_LEN]; |
| 172 |
int article_count = 0; |
int article_count = 0; |
| 173 |
int ret = 0; |
int ret = 0; |
| 174 |
int i; |
int i; |
| 183 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 184 |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
| 185 |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
| 186 |
"bbs_content.content " |
"sub_ip, bbs_content.content " |
| 187 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 188 |
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
| 189 |
start_aid, article_count_limit); |
start_aid, article_count_limit); |
| 236 |
|
|
| 237 |
article.sub_dt = atol(row[i++]); |
article.sub_dt = atol(row[i++]); |
| 238 |
|
|
| 239 |
|
strncpy(sub_ip, row[i++], sizeof(sub_ip) - 1); |
| 240 |
|
sub_ip[sizeof(sub_ip) - 1] = '\0'; |
| 241 |
|
ip_mask(sub_ip, 1, '*'); |
| 242 |
|
|
| 243 |
// release lock of last section if different from current one |
// release lock of last section if different from current one |
| 244 |
if (!global_lock && article.sid != last_sid && last_sid != 0) |
if (!global_lock && article.sid != last_sid && last_sid != 0) |
| 245 |
{ |
{ |
| 292 |
|
|
| 293 |
article_count++; |
article_count++; |
| 294 |
|
|
| 295 |
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) |
| 296 |
{ |
{ |
| 297 |
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); |
| 298 |
ret = -4; |
ret = -4; |
| 375 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 376 |
SECTION_LIST *p_section = NULL; |
SECTION_LIST *p_section = NULL; |
| 377 |
SECTION_LIST *p_section_dest; |
SECTION_LIST *p_section_dest; |
| 378 |
|
char sub_ip[IP_ADDR_LEN]; |
| 379 |
int32_t last_sid = 0; |
int32_t last_sid = 0; |
| 380 |
int32_t sid_dest; |
int32_t sid_dest; |
| 381 |
int op_count = 0; |
int op_count = 0; |
| 472 |
break; |
break; |
| 473 |
case 'M': // Modify article |
case 'M': // Modify article |
| 474 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 475 |
"SELECT bbs.CID, bbs_content.content " |
"SELECT bbs.CID, sub_ip, bbs_content.content " |
| 476 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 477 |
"WHERE bbs.AID = %d", |
"WHERE bbs.AID = %d", |
| 478 |
p_article->aid); |
p_article->aid); |
| 493 |
{ |
{ |
| 494 |
p_article->cid = atoi(row2[0]); |
p_article->cid = atoi(row2[0]); |
| 495 |
|
|
| 496 |
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); |
| 497 |
|
sub_ip[sizeof(sub_ip) - 1] = '\0'; |
| 498 |
|
ip_mask(sub_ip, 1, '*'); |
| 499 |
|
|
| 500 |
|
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[2], sub_ip, 0) < 0) |
| 501 |
{ |
{ |
| 502 |
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); |
| 503 |
ret = -4; |
ret = -4; |
| 635 |
{ |
{ |
| 636 |
SYS_child_process_count++; |
SYS_child_process_count++; |
| 637 |
section_list_loader_pid = pid; |
section_list_loader_pid = pid; |
| 638 |
log_std("Section list loader process (%d) start\n", pid); |
log_common("Section list loader process (pid = %d) start\n", pid); |
| 639 |
return 0; |
return 0; |
| 640 |
} |
} |
| 641 |
else if (pid < 0) // Error |
else if (pid < 0) // Error |
| 691 |
load_count = article_block_article_count() - article_count; |
load_count = article_block_article_count() - article_count; |
| 692 |
if (load_count > 0) |
if (load_count > 0) |
| 693 |
{ |
{ |
| 694 |
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()); |
| 695 |
} |
} |
| 696 |
|
|
| 697 |
if (SYS_section_list_reload) |
if (SYS_section_list_reload) |
| 717 |
|
|
| 718 |
if (last_article_op_log_mid > last_mid) |
if (last_article_op_log_mid > last_mid) |
| 719 |
{ |
{ |
| 720 |
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); |
| 721 |
} |
} |
| 722 |
|
|
| 723 |
if (SYS_section_list_reload) |
if (SYS_section_list_reload) |
| 725 |
continue; |
continue; |
| 726 |
} |
} |
| 727 |
|
|
| 728 |
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++) |
| 729 |
{ |
{ |
| 730 |
sleep(1); |
sleep(1); |
| 731 |
} |
} |
| 738 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 739 |
detach_trie_dict_shm(); |
detach_trie_dict_shm(); |
| 740 |
|
|
| 741 |
log_std("Section list loader process exit normally\n"); |
log_common("Section list loader process exit normally\n"); |
| 742 |
log_end(); |
log_end(); |
| 743 |
|
|
| 744 |
section_list_loader_pid = 0; |
section_list_loader_pid = 0; |
| 830 |
} |
} |
| 831 |
|
|
| 832 |
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, |
| 833 |
int *p_page_id, int *p_offset, int *p_article_count) |
int *p_page_id, int *p_visible_offset, int *p_article_count) |
| 834 |
{ |
{ |
| 835 |
ARTICLE *p_article = NULL; |
const ARTICLE *p_article = NULL; |
| 836 |
ARTICLE *p_next; |
ARTICLE *p_tmp; |
| 837 |
int32_t aid = 0; |
int32_t aid = 0; |
| 838 |
|
int page_id; |
| 839 |
|
int offset; |
| 840 |
int ret = 0; |
int ret = 0; |
| 841 |
|
int i; |
| 842 |
|
|
| 843 |
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) |
| 844 |
{ |
{ |
| 845 |
log_error("locate_article_in_section() NULL pointer error\n"); |
log_error("locate_article_in_section() NULL pointer error\n"); |
| 846 |
return -1; |
return -1; |
| 859 |
} |
} |
| 860 |
else if (direction == 1) |
else if (direction == 1) |
| 861 |
{ |
{ |
| 862 |
aid = p_article_cur->p_topic_next->aid; |
p_article = p_article_cur; |
| 863 |
if (aid <= p_article_cur->aid) |
do |
| 864 |
{ |
{ |
| 865 |
aid = 0; |
p_article = p_article->p_topic_next; |
| 866 |
} |
} while (p_article != p_article_cur && p_article->visible == 0); |
| 867 |
|
|
| 868 |
|
aid = (p_article->aid > p_article_cur->aid ? p_article->aid : 0); |
| 869 |
} |
} |
| 870 |
else if (direction == -1) |
else if (direction == -1) |
| 871 |
{ |
{ |
| 872 |
aid = p_article_cur->p_topic_prior->aid; |
p_article = p_article_cur; |
| 873 |
if (aid >= p_article_cur->aid) |
do |
| 874 |
{ |
{ |
| 875 |
aid = 0; |
p_article = p_article->p_topic_prior; |
| 876 |
} |
} while (p_article != p_article_cur && p_article->visible == 0); |
| 877 |
|
|
| 878 |
|
aid = (p_article->aid < p_article_cur->aid ? p_article->aid : 0); |
| 879 |
} |
} |
| 880 |
|
|
| 881 |
|
p_article = NULL; |
| 882 |
|
|
| 883 |
if (aid > 0) |
if (aid > 0) |
| 884 |
{ |
{ |
| 885 |
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); |
| 886 |
if (p_article != NULL) |
if (p_article != NULL) |
| 887 |
{ |
{ |
| 888 |
*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); |
| 889 |
|
|
| 890 |
|
p_article = p_section->p_page_first_article[page_id]; |
| 891 |
|
for (i = 0; i < *p_article_count;) |
| 892 |
|
{ |
| 893 |
|
if (p_article->visible) |
| 894 |
|
{ |
| 895 |
|
if (p_article->aid == aid) |
| 896 |
|
{ |
| 897 |
|
*p_page_id = page_id; |
| 898 |
|
*p_visible_offset = i; |
| 899 |
|
break; |
| 900 |
|
} |
| 901 |
|
i++; |
| 902 |
|
if (i >= *p_article_count) |
| 903 |
|
{ |
| 904 |
|
log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id); |
| 905 |
|
p_article = NULL; |
| 906 |
|
} |
| 907 |
|
} |
| 908 |
|
p_article = p_article->p_next; |
| 909 |
|
} |
| 910 |
} |
} |
| 911 |
} |
} |
| 912 |
|
|