/[LeafOK_CVS]/lbbs/include/section_list.h
ViewVC logotype

Contents of /lbbs/include/section_list.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.38 - (show annotations)
Thu Nov 20 10:20:51 2025 UTC (3 months, 3 weeks ago) by sysadm
Branch: MAIN
Changes since 1.37: +12 -0 lines
Content type: text/x-chdr
Add alternative POSIX semaphore based rd/rw (un)lock in section_list

1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2 /*
3 * section_list
4 * - data models and basic operations of section and article
5 *
6 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 */
8
9 #ifndef _SECTION_LIST_H_
10 #define _SECTION_LIST_H_
11
12 #include "bbs.h"
13 #include "common.h"
14 #include "menu.h"
15 #include <time.h>
16
17 #ifdef HAVE_SYSTEM_V
18 #include <sys/sem.h>
19 #else
20 #include <semaphore.h>
21 #endif
22
23 enum section_list_constant_t
24 {
25 BBS_article_title_max_len = 160,
26 #ifdef __CYGWIN__
27 BBS_article_limit_per_section = 10000,
28 #else
29 BBS_article_limit_per_section = 50000,
30 #endif
31 BBS_article_limit_per_page = 20,
32
33 BBS_ontop_article_limit_per_section = 10,
34
35 BBS_article_count_per_block = 1000,
36 };
37
38 struct article_t
39 {
40 int32_t aid;
41 int32_t tid;
42 int32_t sid;
43 int32_t cid;
44 int32_t uid;
45 struct article_t *p_prior; // prior article
46 struct article_t *p_next; // next article
47 struct article_t *p_topic_prior; // same topic
48 struct article_t *p_topic_next; // same topic
49 int8_t visible;
50 int8_t excerption;
51 int8_t ontop;
52 int8_t lock;
53 int8_t transship;
54 char username[BBS_username_max_len + 1];
55 char nickname[BBS_nickname_max_len + 1];
56 char title[BBS_article_title_max_len + 1];
57 time_t sub_dt;
58 };
59 typedef struct article_t ARTICLE;
60
61 struct section_list_t
62 {
63 int32_t sid;
64 int32_t class_id;
65 int8_t enable;
66 char sname[BBS_section_name_max_len + 1];
67 char stitle[BBS_section_title_max_len + 1];
68 char master_list[(BBS_username_max_len + 1) * 3 + 1];
69 int read_user_level;
70 int write_user_level;
71 int32_t article_count;
72 int32_t topic_count;
73 int32_t visible_article_count;
74 int32_t visible_topic_count;
75 ARTICLE *p_article_head;
76 ARTICLE *p_article_tail;
77 ARTICLE *p_page_first_article[BBS_article_limit_per_section / BBS_article_limit_per_page];
78 int32_t page_count;
79 int32_t last_page_visible_article_count;
80 ARTICLE *p_ontop_articles[BBS_ontop_article_limit_per_section];
81 int32_t ontop_article_count;
82 MENU_SET ex_menu_set;
83 time_t ex_menu_tm;
84 };
85 typedef struct section_list_t SECTION_LIST;
86
87 struct section_list_pool_t
88 {
89 size_t shm_size;
90 SECTION_LIST sections[BBS_max_section];
91 int section_count;
92 #ifndef HAVE_SYSTEM_V
93 sem_t sem[BBS_max_section + 1];
94 uint16_t read_lock_count[BBS_max_section + 1];
95 uint16_t write_lock_count[BBS_max_section + 1];
96 #else
97 int semid;
98 #endif
99 TRIE_NODE *p_trie_dict_section_by_name;
100 TRIE_NODE *p_trie_dict_section_by_sid;
101 };
102 typedef struct section_list_pool_t SECTION_LIST_POOL;
103
104 extern SECTION_LIST_POOL *p_section_list_pool;
105
106 // article_block_count * BBS_article_count_per_block should be
107 // no less than BBS_article_limit_per_section * BBS_max_section,
108 // in order to allocate enough memory for blocks
109 extern int article_block_init(const char *filename, int block_count);
110 extern void article_block_cleanup(void);
111
112 extern int set_article_block_shm_readonly(void);
113 extern int detach_article_block_shm(void);
114
115 extern int article_block_reset(void);
116
117 extern ARTICLE *article_block_find_by_aid(int32_t aid);
118 extern ARTICLE *article_block_find_by_index(int index);
119
120 extern int32_t article_block_last_aid(void);
121 extern int article_block_article_count(void);
122
123 extern int article_count_of_topic(int32_t aid);
124
125 extern int section_list_init(const char *filename);
126 extern void section_list_cleanup(void);
127
128 extern int set_section_list_shm_readonly(void);
129 extern int detach_section_list_shm(void);
130
131 extern SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_list);
132 extern int section_list_update(SECTION_LIST *p_section, const char *sname, const char *stitle, const char *master_list);
133 extern void section_list_reset_articles(SECTION_LIST *p_section);
134 extern SECTION_LIST *section_list_find_by_name(const char *sname);
135 extern SECTION_LIST *section_list_find_by_sid(int32_t sid);
136 extern int get_section_index(SECTION_LIST *p_section);
137
138 // sname could be NULL, or pointer to char[] in size >= sizeof(SECTION_LIST.sname)
139 // stitle could be NULL, or pointer to char[] in size >= sizeof(SECTION_LIST.stitle)
140 // master_list could be NULL, or pointer to char[] in size >= sizeof(SECTION_LIST.master_list)
141 extern int get_section_info(SECTION_LIST *p_section, char *sname, char *stitle, char *master_list);
142
143 extern int section_list_append_article(SECTION_LIST *p_section, const ARTICLE *p_article_src);
144 extern int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_t visible);
145
146 extern int section_list_update_article_ontop(SECTION_LIST *p_section, ARTICLE *p_article);
147 extern int section_list_page_count_with_ontop(SECTION_LIST *p_section);
148 extern int section_list_page_article_count_with_ontop(SECTION_LIST *p_section, int32_t page_id);
149
150 // *p_page, *p_offset will be set as page / offset of the article with aid in *p_section (including both visible and invisible articles)
151 // *pp_next will be set as pointer to the next article of the article with aid
152 // *pp_next will be set as head article of the section if the article with aid locates at the tail of the section
153 extern 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);
154
155 extern int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid);
156 extern int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section_dest, int32_t aid);
157
158 extern int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec);
159 extern int section_list_try_rw_lock(SECTION_LIST *p_section, int wait_sec);
160 extern int section_list_rd_unlock(SECTION_LIST *p_section);
161 extern int section_list_rw_unlock(SECTION_LIST *p_section);
162 extern int section_list_rd_lock(SECTION_LIST *p_section);
163 extern int section_list_rw_lock(SECTION_LIST *p_section);
164
165 #endif //_SECTION_LIST_H_

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1