/[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.47 - (show annotations)
Wed Nov 5 14:59:31 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.46: +11 -0 lines
Content type: text/x-csrc
Add feature: update user introduction

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

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