| 42 |
#define SECTION_TRY_LOCK_WAIT_TIME 1 // second |
#define SECTION_TRY_LOCK_WAIT_TIME 1 // second |
| 43 |
#define SECTION_TRY_LOCK_TIMES 10 |
#define SECTION_TRY_LOCK_TIMES 10 |
| 44 |
|
|
| 45 |
#define ARTICLE_BLOCK_PER_SHM 1000 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate |
#define ARTICLE_BLOCK_PER_SHM 1000 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate |
| 46 |
#define ARTICLE_BLOCK_SHM_COUNT_LIMIT 80 // limited by length (8-bit) of proj_id in ftok(path, proj_id) |
#define ARTICLE_BLOCK_SHM_COUNT_LIMIT 80 // limited by length (8-bit) of proj_id in ftok(path, proj_id) |
| 47 |
#define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT) |
#define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT) |
| 48 |
|
|
| 555 |
p_section_list_pool = NULL; |
p_section_list_pool = NULL; |
| 556 |
} |
} |
| 557 |
|
|
| 558 |
|
void section_list_ex_menu_set_cleanup(void) |
| 559 |
|
{ |
| 560 |
|
int i; |
| 561 |
|
|
| 562 |
|
for (i = 0; i < p_section_list_pool->section_count; i++) |
| 563 |
|
{ |
| 564 |
|
if (p_section_list_pool->sections[i].ex_menu_tm > 0) |
| 565 |
|
{ |
| 566 |
|
unload_menu(&(p_section_list_pool->sections[i].ex_menu_set)); |
| 567 |
|
} |
| 568 |
|
} |
| 569 |
|
} |
| 570 |
|
|
| 571 |
int set_section_list_shm_readonly(void) |
int set_section_list_shm_readonly(void) |
| 572 |
{ |
{ |
| 573 |
int shmid; |
int shmid; |
| 643 |
p_section = p_section_list_pool->sections + p_section_list_pool->section_count; |
p_section = p_section_list_pool->sections + p_section_list_pool->section_count; |
| 644 |
|
|
| 645 |
p_section->sid = sid; |
p_section->sid = sid; |
| 646 |
|
p_section->ex_menu_tm = 0; |
| 647 |
|
|
| 648 |
strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1); |
strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1); |
| 649 |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 684 |
|
|
| 685 |
p_section->page_count = 0; |
p_section->page_count = 0; |
| 686 |
p_section->last_page_visible_article_count = 0; |
p_section->last_page_visible_article_count = 0; |
| 687 |
|
|
| 688 |
|
p_section->ontop_article_count = 0; |
| 689 |
} |
} |
| 690 |
|
|
| 691 |
SECTION_LIST *section_list_find_by_name(const char *sname) |
SECTION_LIST *section_list_find_by_name(const char *sname) |
| 876 |
p_section->last_page_visible_article_count++; |
p_section->last_page_visible_article_count++; |
| 877 |
} |
} |
| 878 |
|
|
| 879 |
|
if (p_article->ontop && section_list_update_article_ontop(p_section, p_article) < 0) |
| 880 |
|
{ |
| 881 |
|
log_error("section_list_update_article_ontop(sid=%d, aid=%d) error\n", |
| 882 |
|
p_section->sid, p_article->aid); |
| 883 |
|
return -5; |
| 884 |
|
} |
| 885 |
|
|
| 886 |
return 0; |
return 0; |
| 887 |
} |
} |
| 888 |
|
|
| 894 |
|
|
| 895 |
if (p_section == NULL) |
if (p_section == NULL) |
| 896 |
{ |
{ |
| 897 |
log_error("section_list_set_article_visible() NULL pointer error\n"); |
log_error("NULL pointer error\n"); |
| 898 |
return -2; |
return -1; |
| 899 |
} |
} |
| 900 |
|
|
| 901 |
p_article = article_block_find_by_aid(aid); |
p_article = article_block_find_by_aid(aid); |
| 906 |
|
|
| 907 |
if (p_section->sid != p_article->sid) |
if (p_section->sid != p_article->sid) |
| 908 |
{ |
{ |
| 909 |
log_error("section_list_set_article_visible() error: section sid %d != article sid %d\n", p_section->sid, p_article->sid); |
log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid); |
| 910 |
return -2; |
return -2; |
| 911 |
} |
} |
| 912 |
|
|
| 957 |
return affected_count; |
return affected_count; |
| 958 |
} |
} |
| 959 |
|
|
| 960 |
|
int section_list_update_article_ontop(SECTION_LIST *p_section, ARTICLE *p_article) |
| 961 |
|
{ |
| 962 |
|
int i; |
| 963 |
|
|
| 964 |
|
if (p_section == NULL || p_article == NULL) |
| 965 |
|
{ |
| 966 |
|
log_error("NULL pointer error\n"); |
| 967 |
|
return -1; |
| 968 |
|
} |
| 969 |
|
|
| 970 |
|
if (p_section->sid != p_article->sid) |
| 971 |
|
{ |
| 972 |
|
log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid); |
| 973 |
|
return -2; |
| 974 |
|
} |
| 975 |
|
|
| 976 |
|
if (p_article->ontop) |
| 977 |
|
{ |
| 978 |
|
for (i = 0; i < p_section->ontop_article_count; i++) |
| 979 |
|
{ |
| 980 |
|
if (p_section->p_ontop_articles[i]->aid == p_article->aid) |
| 981 |
|
{ |
| 982 |
|
log_error("Inconsistent state found: article %d already ontop in section %d\n", p_article->aid, p_section->sid); |
| 983 |
|
return 0; |
| 984 |
|
} |
| 985 |
|
else if (p_section->p_ontop_articles[i]->aid > p_article->aid) |
| 986 |
|
{ |
| 987 |
|
break; |
| 988 |
|
} |
| 989 |
|
} |
| 990 |
|
|
| 991 |
|
// Remove the oldest one if the array of ontop articles is full |
| 992 |
|
if (p_section->ontop_article_count >= BBS_ontop_article_limit_per_section) |
| 993 |
|
{ |
| 994 |
|
if (i == 0) // p_article is the oldest one |
| 995 |
|
{ |
| 996 |
|
return 0; |
| 997 |
|
} |
| 998 |
|
memmove((void *)(p_section->p_ontop_articles), |
| 999 |
|
(void *)(p_section->p_ontop_articles + 1), |
| 1000 |
|
sizeof(ARTICLE *) * (size_t)(i - 1)); |
| 1001 |
|
p_section->ontop_article_count--; |
| 1002 |
|
i--; |
| 1003 |
|
} |
| 1004 |
|
else |
| 1005 |
|
{ |
| 1006 |
|
memmove((void *)(p_section->p_ontop_articles + i + 1), |
| 1007 |
|
(void *)(p_section->p_ontop_articles + i), |
| 1008 |
|
sizeof(ARTICLE *) * (size_t)(p_section->ontop_article_count - i)); |
| 1009 |
|
} |
| 1010 |
|
|
| 1011 |
|
p_section->p_ontop_articles[i] = p_article; |
| 1012 |
|
p_section->ontop_article_count++; |
| 1013 |
|
|
| 1014 |
|
// TODO: debug |
| 1015 |
|
} |
| 1016 |
|
else // ontop == 0 |
| 1017 |
|
{ |
| 1018 |
|
for (i = 0; i < p_section->ontop_article_count; i++) |
| 1019 |
|
{ |
| 1020 |
|
if (p_section->p_ontop_articles[i]->aid == p_article->aid) |
| 1021 |
|
{ |
| 1022 |
|
break; |
| 1023 |
|
} |
| 1024 |
|
} |
| 1025 |
|
if (i == p_section->ontop_article_count) // not found |
| 1026 |
|
{ |
| 1027 |
|
log_error("Inconsistent state found: article %d not ontop in section %d\n", p_article->aid, p_section->sid); |
| 1028 |
|
return 0; |
| 1029 |
|
} |
| 1030 |
|
|
| 1031 |
|
memmove((void *)(p_section->p_ontop_articles + i), |
| 1032 |
|
(void *)(p_section->p_ontop_articles + i + 1), |
| 1033 |
|
sizeof(ARTICLE *) * (size_t)(p_section->ontop_article_count - i - 1)); |
| 1034 |
|
p_section->ontop_article_count--; |
| 1035 |
|
} |
| 1036 |
|
|
| 1037 |
|
return 0; |
| 1038 |
|
} |
| 1039 |
|
|
| 1040 |
|
int section_list_page_count_with_ontop(SECTION_LIST *p_section) |
| 1041 |
|
{ |
| 1042 |
|
int page_count; |
| 1043 |
|
|
| 1044 |
|
if (p_section == NULL) |
| 1045 |
|
{ |
| 1046 |
|
log_error("NULL pointer error\n"); |
| 1047 |
|
return -1; |
| 1048 |
|
} |
| 1049 |
|
|
| 1050 |
|
page_count = p_section->page_count - 1 + |
| 1051 |
|
(p_section->last_page_visible_article_count + p_section->ontop_article_count) / BBS_article_limit_per_page + |
| 1052 |
|
((p_section->last_page_visible_article_count + p_section->ontop_article_count) % BBS_article_limit_per_page == 0 ? 0 : 1); |
| 1053 |
|
|
| 1054 |
|
return page_count; |
| 1055 |
|
} |
| 1056 |
|
|
| 1057 |
|
int section_list_page_article_count_with_ontop(SECTION_LIST *p_section, int32_t page_id) |
| 1058 |
|
{ |
| 1059 |
|
if (p_section == NULL) |
| 1060 |
|
{ |
| 1061 |
|
log_error("NULL pointer error\n"); |
| 1062 |
|
return -1; |
| 1063 |
|
} |
| 1064 |
|
|
| 1065 |
|
if (page_id < p_section->page_count - 1) |
| 1066 |
|
{ |
| 1067 |
|
return BBS_article_limit_per_page; |
| 1068 |
|
} |
| 1069 |
|
else // if (page_id >= p_section->page_count - 1) |
| 1070 |
|
{ |
| 1071 |
|
return MAX(0, (p_section->last_page_visible_article_count + p_section->ontop_article_count - |
| 1072 |
|
BBS_article_limit_per_page * (page_id - p_section->page_count + 1))); |
| 1073 |
|
} |
| 1074 |
|
} |
| 1075 |
|
|
| 1076 |
ARTICLE *section_list_find_article_with_offset(SECTION_LIST *p_section, int32_t aid, int32_t *p_page, int32_t *p_offset, ARTICLE **pp_next) |
ARTICLE *section_list_find_article_with_offset(SECTION_LIST *p_section, int32_t aid, int32_t *p_page, int32_t *p_offset, ARTICLE **pp_next) |
| 1077 |
{ |
{ |
| 1078 |
ARTICLE *p_article; |
ARTICLE *p_article; |