| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
#include "article_cache.h" |
#include "article_cache.h" |
| 18 |
|
#include "article_view_log.h" |
| 19 |
#include "bbs.h" |
#include "bbs.h" |
| 20 |
#include "database.h" |
#include "database.h" |
| 21 |
#include "ip_mask.h" |
#include "ip_mask.h" |
| 22 |
#include "log.h" |
#include "log.h" |
| 23 |
#include "menu.h" |
#include "menu.h" |
| 24 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 25 |
|
#include "user_list.h" |
| 26 |
|
#include "user_priv.h" |
| 27 |
#include <errno.h> |
#include <errno.h> |
| 28 |
#include <signal.h> |
#include <signal.h> |
| 29 |
#include <stdio.h> |
#include <stdio.h> |
| 138 |
break; |
break; |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1); |
if (section_list_update(p_section, row[1], row[2], master_list) < 0) |
| 142 |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
{ |
| 143 |
strncpy(p_section->stitle, row[2], sizeof(p_section->stitle) - 1); |
log_error("section_list_update(sid=%d) error\n", p_section->sid); |
| 144 |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
ret = -4; |
| 145 |
strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1); |
break; |
| 146 |
p_section->master_list[sizeof(p_section->master_list) - 1] = '\0'; |
} |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
p_section->class_id = atoi(row[3]); |
p_section->class_id = atoi(row[3]); |
| 152 |
p_section->enable = (int8_t)atoi(row[6]); |
p_section->enable = (int8_t)atoi(row[6]); |
| 153 |
|
|
| 154 |
// Update gen_ex menu set |
// Update gen_ex menu set |
| 155 |
if (update_gen_ex && p_section->enable && atoi(row[7]) > p_section->ex_menu_tm) |
if (update_gen_ex && p_section->enable && atol(row[7] == NULL ? "0" : row[7]) > p_section->ex_menu_tm) |
| 156 |
{ |
{ |
| 157 |
snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid); |
snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid); |
| 158 |
|
|
| 690 |
int article_count; |
int article_count; |
| 691 |
int load_count; |
int load_count; |
| 692 |
int last_mid; |
int last_mid; |
| 693 |
int i; |
time_t tm_section_list_reload = 0; |
| 694 |
|
time_t tm_user_list_reload = time(NULL); |
| 695 |
|
time_t tm_user_online_list_reload = time(NULL); |
| 696 |
|
|
| 697 |
if (section_list_loader_pid != 0) |
if (section_list_loader_pid != 0) |
| 698 |
{ |
{ |
| 720 |
|
|
| 721 |
// Detach menu in shared memory |
// Detach menu in shared memory |
| 722 |
detach_menu_shm(&bbs_menu); |
detach_menu_shm(&bbs_menu); |
| 723 |
|
detach_menu_shm(&top10_menu); |
| 724 |
|
|
| 725 |
// Set signal handler |
// Set signal handler |
| 726 |
act.sa_handler = SIG_DFL; |
act.sa_handler = SIG_DFL; |
| 737 |
// Do section data loader periodically |
// Do section data loader periodically |
| 738 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 739 |
{ |
{ |
| 740 |
|
tm_section_list_reload = time(NULL); |
| 741 |
|
|
| 742 |
if (SYS_conf_reload) |
if (SYS_conf_reload) |
| 743 |
{ |
{ |
| 744 |
SYS_conf_reload = 0; |
SYS_conf_reload = 0; |
| 804 |
log_common("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); |
| 805 |
} |
} |
| 806 |
|
|
| 807 |
if (SYS_conf_reload) |
// Reload user list |
| 808 |
|
if (time(NULL) - tm_user_list_reload >= BBS_user_list_load_interval) |
| 809 |
{ |
{ |
| 810 |
continue; |
if (user_list_pool_reload(0) < 0) |
| 811 |
|
{ |
| 812 |
|
log_error("user_list_pool_reload(all_user) error\n"); |
| 813 |
|
} |
| 814 |
|
|
| 815 |
|
if (user_stat_update() < 0) |
| 816 |
|
{ |
| 817 |
|
log_error("user_stat_update() error\n"); |
| 818 |
|
} |
| 819 |
|
|
| 820 |
|
tm_user_list_reload = time(NULL); |
| 821 |
|
} |
| 822 |
|
|
| 823 |
|
// Reload user online list |
| 824 |
|
if (time(NULL) - tm_user_online_list_reload >= BBS_user_online_list_load_interval) |
| 825 |
|
{ |
| 826 |
|
if (user_list_pool_reload(1) < 0) |
| 827 |
|
{ |
| 828 |
|
log_error("user_list_pool_reload(online_user) error\n"); |
| 829 |
|
} |
| 830 |
|
|
| 831 |
|
tm_user_online_list_reload = time(NULL); |
| 832 |
} |
} |
| 833 |
|
|
| 834 |
for (i = 0; i < BBS_section_list_load_interval && !SYS_server_exit && !SYS_conf_reload; i++) |
// Wait for BBS_section_list_load_interval seconds |
| 835 |
|
while (!SYS_server_exit && time(NULL) - tm_section_list_reload < BBS_section_list_load_interval) |
| 836 |
{ |
{ |
| 837 |
sleep(1); |
sleep(1); |
| 838 |
} |
} |
| 849 |
detach_section_list_shm(); |
detach_section_list_shm(); |
| 850 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 851 |
detach_trie_dict_shm(); |
detach_trie_dict_shm(); |
| 852 |
|
detach_user_list_pool_shm(); |
| 853 |
|
|
| 854 |
log_common("Section list loader process exit normally\n"); |
log_common("Section list loader process exit normally\n"); |
| 855 |
log_end(); |
log_end(); |
| 977 |
} |
} |
| 978 |
else if (direction == 1) |
else if (direction == 1) |
| 979 |
{ |
{ |
| 980 |
for (p_article = p_article_cur, p_article_last = p_article_cur; |
for (p_article_last = p_article_cur, p_article = p_article_cur->p_topic_next; |
| 981 |
step > 0 && p_article->p_topic_next->aid > p_article_cur->aid; |
step > 0 && p_article->aid > p_article_cur->aid; |
| 982 |
p_article = p_article->p_topic_next) |
p_article = p_article->p_topic_next) |
| 983 |
{ |
{ |
| 984 |
if (p_article->visible) |
if (p_article->visible) |
| 987 |
p_article_last = p_article; |
p_article_last = p_article; |
| 988 |
} |
} |
| 989 |
} |
} |
| 990 |
if (!p_article->visible) |
p_article = p_article_last; |
|
{ |
|
|
p_article = p_article_last; |
|
|
} |
|
| 991 |
|
|
| 992 |
aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0); |
aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0); |
| 993 |
} |
} |
| 994 |
else if (direction == -1) |
else if (direction == -1) |
| 995 |
{ |
{ |
| 996 |
for (p_article = p_article_cur, p_article_last = p_article_cur; |
for (p_article_last = p_article_cur, p_article = p_article_cur->p_topic_prior; |
| 997 |
step > 0 && p_article->p_topic_prior->aid < p_article_cur->aid; |
step > 0 && p_article->aid < p_article_cur->aid; |
| 998 |
p_article = p_article->p_topic_prior) |
p_article = p_article->p_topic_prior) |
| 999 |
{ |
{ |
| 1000 |
if (p_article->visible) |
if (p_article->visible) |
| 1003 |
p_article_last = p_article; |
p_article_last = p_article; |
| 1004 |
} |
} |
| 1005 |
} |
} |
| 1006 |
if (!p_article->visible) |
p_article = p_article_last; |
|
{ |
|
|
p_article = p_article_last; |
|
|
} |
|
| 1007 |
|
|
| 1008 |
aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0); |
aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0); |
| 1009 |
} |
} |
| 1054 |
return (ret < 0 ? ret : (p_article == NULL ? 0 : 1)); |
return (ret < 0 ? ret : (p_article == NULL ? 0 : 1)); |
| 1055 |
} |
} |
| 1056 |
|
|
| 1057 |
|
int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, const ARTICLE **pp_article_unread) |
| 1058 |
|
{ |
| 1059 |
|
ARTICLE *p_article; |
| 1060 |
|
int ret = 0; |
| 1061 |
|
|
| 1062 |
|
if (p_section == NULL || p_article_cur == NULL || pp_article_unread == NULL) |
| 1063 |
|
{ |
| 1064 |
|
log_error("NULL pointer error\n"); |
| 1065 |
|
return -1; |
| 1066 |
|
} |
| 1067 |
|
|
| 1068 |
|
if (p_article_cur->sid != p_section->sid) |
| 1069 |
|
{ |
| 1070 |
|
log_error("Inconsistent SID\n"); |
| 1071 |
|
return -1; |
| 1072 |
|
} |
| 1073 |
|
|
| 1074 |
|
// acquire lock of section |
| 1075 |
|
if ((ret = section_list_rd_lock(p_section)) < 0) |
| 1076 |
|
{ |
| 1077 |
|
log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); |
| 1078 |
|
return -2; |
| 1079 |
|
} |
| 1080 |
|
|
| 1081 |
|
*pp_article_unread = NULL; |
| 1082 |
|
|
| 1083 |
|
for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next) |
| 1084 |
|
{ |
| 1085 |
|
if (p_article->visible && p_article->uid != BBS_priv.uid && !article_view_log_is_viewed(p_article->aid, &BBS_article_view_log)) |
| 1086 |
|
{ |
| 1087 |
|
*pp_article_unread = p_article; |
| 1088 |
|
break; |
| 1089 |
|
} |
| 1090 |
|
} |
| 1091 |
|
|
| 1092 |
|
// release lock of section |
| 1093 |
|
if (section_list_rd_unlock(p_section) < 0) |
| 1094 |
|
{ |
| 1095 |
|
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
| 1096 |
|
return -2; |
| 1097 |
|
} |
| 1098 |
|
|
| 1099 |
|
return (p_article != NULL && p_article != p_article_cur ? 1 : 0); |
| 1100 |
|
} |
| 1101 |
|
|
| 1102 |
int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set) |
int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set) |
| 1103 |
{ |
{ |
| 1104 |
int ret = 0; |
int ret = 0; |