/[LeafOK_CVS]/lbbs/src/menu_proc.c
ViewVC logotype

Contents of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.41 - (show annotations)
Sat Oct 18 12:06:10 2025 UTC (4 months, 4 weeks ago) by sysadm
Branch: MAIN
Changes since 1.40: +10 -3 lines
Content type: text/x-csrc
Refine code to keep compatible with gcc -Wpedantic option

1 /***************************************************************************
2 menu_proc.c - description
3 -------------------
4 Copyright : (C) 2004-2025 by Leaflet
5 Email : leaflet@leafok.com
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 3 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17 #include "article_cache.h"
18 #include "article_favor_display.h"
19 #include "article_view_log.h"
20 #include "bbs.h"
21 #include "bbs_cmd.h"
22 #include "common.h"
23 #include "io.h"
24 #include "log.h"
25 #include "login.h"
26 #include "menu.h"
27 #include "section_list_display.h"
28 #include "screen.h"
29 #include "user_priv.h"
30 #include <dlfcn.h>
31 #include <errno.h>
32 #include <signal.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <time.h>
36 #include <unistd.h>
37 #include <sys/types.h>
38
39 int list_section(void *param)
40 {
41 section_list_display(param, 0);
42
43 return REDRAW;
44 }
45
46 typedef union exec_handler_t{
47 void *p;
48 int (*handler)();
49 } exec_handler;
50
51 int exec_mbem(void *param)
52 {
53 void *hdll;
54 exec_handler func;
55 char *c, *s;
56 char buf[FILE_PATH_LEN];
57
58 strncpy(buf, (const char *)param, sizeof(buf) - 1);
59 buf[sizeof(buf) - 1] = '\0';
60
61 s = strstr(buf, "@mod:");
62 if (s)
63 {
64 c = strstr(s + 5, "#");
65 if (c)
66 {
67 *c = 0;
68 c++;
69 }
70
71 hdll = dlopen(s + 5, RTLD_LAZY);
72
73 if (hdll)
74 {
75 char *error;
76
77 if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
78 {
79 func.handler();
80 }
81 else if ((error = dlerror()) != NULL)
82 {
83 clearscr();
84 prints("%s\r\n", error);
85 press_any_key();
86 }
87 dlclose(hdll);
88 }
89 else
90 {
91 clearscr();
92 prints("加载库文件 [%s] 失败!!\r\n", s + 5);
93 prints("失败原因:%s\r\n", dlerror());
94 press_any_key();
95 }
96 }
97
98 return REDRAW;
99 }
100
101 int exit_bbs(void *param)
102 {
103 return EXITBBS;
104 }
105
106 int license(void *param)
107 {
108 display_file(DATA_LICENSE, 0);
109
110 return REDRAW;
111 }
112
113 int copyright(void *param)
114 {
115 display_file(DATA_COPYRIGHT, 1);
116
117 return REDRAW;
118 }
119
120 int version(void *param)
121 {
122 display_file(DATA_VERSION, 1);
123
124 return REDRAW;
125 }
126
127 int reload_bbs_conf(void *param)
128 {
129 clearscr();
130
131 if (kill(getppid(), SIGHUP) < 0)
132 {
133 log_error("Send SIGHUP signal failed (%d)\n", errno);
134
135 prints("发送指令失败\r\n");
136 }
137 else
138 {
139 prints("已发送指令\r\n");
140 }
141
142 press_any_key();
143
144 return REDRAW;
145 }
146
147 int shutdown_bbs(void *param)
148 {
149 log_common("Notify main process to exit\n");
150
151 if (kill(getppid(), SIGTERM) < 0)
152 {
153 log_error("Send SIGTERM signal failed (%d)\n", errno);
154 }
155
156 return REDRAW;
157 }
158
159 int favor_section_filter(void *param)
160 {
161 MENU_ITEM *p_menu_item = param;
162
163 return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));
164 }
165
166 static int display_ex_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
167 {
168 switch (*p_key)
169 {
170 case 0: // Set msg
171 snprintf(p_ctx->msg, sizeof(p_ctx->msg),
172 "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
173 "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
174 "帮助[\033[32mh\033[33m] |");
175 break;
176 }
177
178 return 0;
179 }
180
181 int view_ex_article(void *param)
182 {
183 ARTICLE_CACHE cache;
184 ARTICLE *p_article;
185 int32_t aid = atoi(param);
186 int ret;
187
188 (void)ret;
189
190 p_article = article_block_find_by_aid(aid);
191 if (p_article == NULL)
192 {
193 log_error("article_block_find_by_aid(%d) error\n", aid);
194 return NOREDRAW;
195 }
196
197 if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
198 {
199 log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
200 return NOREDRAW;
201 }
202
203 if (user_online_update("VIEW_ARTICLE") < 0)
204 {
205 log_error("user_online_update(VIEW_ARTICLE) error\n");
206 }
207
208 ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
209 display_ex_article_key_handler, DATA_READ_HELP);
210
211 if (article_cache_unload(&cache) < 0)
212 {
213 log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
214 }
215
216 // Update article_view_log
217 if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)
218 {
219 log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid);
220 }
221
222 return REDRAW;
223 }
224
225 int list_ex_section(void *param)
226 {
227 SECTION_LIST *p_section;
228
229 p_section = section_list_find_by_name(param);
230 if (p_section == NULL)
231 {
232 log_error("Section %s not found\n", (const char *)param);
233 return -1;
234 }
235
236 if (section_list_ex_dir_display(p_section) < 0)
237 {
238 log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
239 }
240
241 return REDRAW;
242 }
243
244 int show_top10_menu(void *param)
245 {
246 static int show_top10 = 0;
247 int ch = 0;
248
249 if (show_top10)
250 {
251 return NOREDRAW;
252 }
253 show_top10 = 1;
254
255 clearscr();
256 show_top("", BBS_name, "");
257 show_bottom("");
258
259 if (display_menu(&top10_menu) == 0)
260 {
261 while (!SYS_server_exit)
262 {
263 iflush();
264 ch = igetch(100);
265
266 if (ch != KEY_NULL && ch != KEY_TIMEOUT)
267 {
268 BBS_last_access_tm = time(NULL);
269 }
270
271 switch (ch)
272 {
273 case KEY_NULL: // broken pipe
274 log_error("KEY_NULL\n");
275 show_top10 = 0;
276 return 0;
277 case KEY_TIMEOUT:
278 if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
279 {
280 log_error("User input timeout\n");
281 show_top10 = 0;
282 return 0;
283 }
284 continue;
285 case CR:
286 default:
287 switch (menu_control(&top10_menu, ch))
288 {
289 case EXITMENU:
290 ch = EXITMENU;
291 break;
292 case REDRAW:
293 clearscr();
294 show_bottom("");
295 display_menu(&top10_menu);
296 break;
297 case NOREDRAW:
298 case UNKNOWN_CMD:
299 default:
300 break;
301 }
302 }
303
304 if (ch == EXITMENU)
305 {
306 break;
307 }
308 }
309 }
310
311 show_top10 = 0;
312 return REDRAW;
313 }
314
315 int locate_article(void *param)
316 {
317 char buf[MAX_MENUITEM_NAME_LENGTH];
318 char *sname, *aid, *saveptr;
319
320 strncpy(buf, param, sizeof(buf) - 1);
321 buf[sizeof(buf) - 1] = '\0';
322
323 sname = strtok_r(buf, "|", &saveptr);
324 aid = strtok_r(NULL, "|", &saveptr);
325
326 if (sname == NULL || aid == NULL)
327 {
328 log_error("top10_locate(%s) error: invalid parameter\n", param);
329 return NOREDRAW;
330 }
331
332 section_list_display(sname, atoi(aid));
333
334 return REDRAW;
335 }
336
337 int favor_topic(void *param)
338 {
339 if (article_favor_display(&BBS_article_favor) < 0)
340 {
341 log_error("article_favor_display() error\n");
342 }
343
344 return REDRAW;
345 }

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