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

Annotation of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.47 - (hide 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 sysadm 1.44 /* SPDX-License-Identifier: GPL-3.0-or-later */
2     /*
3     * menu_proc
4     * - handler functions of menu commands
5     *
6 sysadm 1.45 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 sysadm 1.44 */
8 sysadm 1.1
9 sysadm 1.28 #include "article_cache.h"
10 sysadm 1.37 #include "article_favor_display.h"
11 sysadm 1.28 #include "article_view_log.h"
12 sysadm 1.1 #include "bbs.h"
13     #include "bbs_cmd.h"
14     #include "common.h"
15 sysadm 1.27 #include "io.h"
16 sysadm 1.7 #include "log.h"
17 sysadm 1.28 #include "login.h"
18 sysadm 1.27 #include "menu.h"
19     #include "section_list_display.h"
20 sysadm 1.7 #include "screen.h"
21 sysadm 1.47 #include "user_info_update.h"
22 sysadm 1.42 #include "user_list_display.h"
23 sysadm 1.20 #include "user_priv.h"
24 sysadm 1.1 #include <dlfcn.h>
25 sysadm 1.4 #include <errno.h>
26 sysadm 1.5 #include <signal.h>
27 sysadm 1.28 #include <stdlib.h>
28 sysadm 1.4 #include <string.h>
29 sysadm 1.1 #include <time.h>
30 sysadm 1.4 #include <unistd.h>
31 sysadm 1.25 #include <sys/types.h>
32 sysadm 1.1
33 sysadm 1.17 int list_section(void *param)
34     {
35 sysadm 1.31 section_list_display(param, 0);
36 sysadm 1.18
37     return REDRAW;
38 sysadm 1.17 }
39    
40 sysadm 1.44 typedef union exec_handler_t
41     {
42 sysadm 1.41 void *p;
43     int (*handler)();
44     } exec_handler;
45    
46 sysadm 1.16 int exec_mbem(void *param)
47 sysadm 1.1 {
48 sysadm 1.6 void *hdll;
49 sysadm 1.41 exec_handler func;
50 sysadm 1.6 char *c, *s;
51 sysadm 1.10 char buf[FILE_PATH_LEN];
52    
53 sysadm 1.16 strncpy(buf, (const char *)param, sizeof(buf) - 1);
54 sysadm 1.10 buf[sizeof(buf) - 1] = '\0';
55 sysadm 1.6
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 sysadm 1.41 if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
73     {
74     func.handler();
75     }
76 sysadm 1.6 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 sysadm 1.30 prints("加载库文件 [%s] 失败!!\r\n", s + 5);
88     prints("失败原因:%s\r\n", dlerror());
89 sysadm 1.6 press_any_key();
90     }
91     }
92    
93     return REDRAW;
94 sysadm 1.1 }
95    
96 sysadm 1.22 int exit_bbs(void *param)
97 sysadm 1.1 {
98 sysadm 1.6 return EXITBBS;
99 sysadm 1.1 }
100    
101 sysadm 1.16 int license(void *param)
102 sysadm 1.1 {
103 sysadm 1.24 display_file(DATA_LICENSE, 0);
104 sysadm 1.6
105     return REDRAW;
106 sysadm 1.1 }
107    
108 sysadm 1.16 int copyright(void *param)
109 sysadm 1.1 {
110 sysadm 1.24 display_file(DATA_COPYRIGHT, 1);
111 sysadm 1.1
112 sysadm 1.6 return REDRAW;
113 sysadm 1.3 }
114    
115 sysadm 1.40 int version(void *param)
116     {
117     display_file(DATA_VERSION, 1);
118    
119     return REDRAW;
120     }
121    
122 sysadm 1.22 int reload_bbs_conf(void *param)
123 sysadm 1.4 {
124 sysadm 1.12 clearscr();
125    
126 sysadm 1.15 if (kill(getppid(), SIGHUP) < 0)
127 sysadm 1.9 {
128 sysadm 1.15 log_error("Send SIGHUP signal failed (%d)\n", errno);
129 sysadm 1.12
130 sysadm 1.30 prints("发送指令失败\r\n");
131 sysadm 1.9 }
132 sysadm 1.12 else
133     {
134 sysadm 1.30 prints("已发送指令\r\n");
135 sysadm 1.12 }
136    
137     press_any_key();
138 sysadm 1.4
139 sysadm 1.6 return REDRAW;
140 sysadm 1.4 }
141    
142 sysadm 1.22 int shutdown_bbs(void *param)
143 sysadm 1.3 {
144 sysadm 1.23 log_common("Notify main process to exit\n");
145 sysadm 1.14
146     if (kill(getppid(), SIGTERM) < 0)
147 sysadm 1.9 {
148 sysadm 1.6 log_error("Send SIGTERM signal failed (%d)\n", errno);
149 sysadm 1.9 }
150 sysadm 1.3
151 sysadm 1.6 return REDRAW;
152 sysadm 1.1 }
153 sysadm 1.20
154 sysadm 1.33 int favor_section_filter(void *param)
155 sysadm 1.20 {
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 sysadm 1.28
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 sysadm 1.30 "| 返回[\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 sysadm 1.28 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 sysadm 1.29
220     int list_ex_section(void *param)
221     {
222     SECTION_LIST *p_section;
223    
224 sysadm 1.36 p_section = section_list_find_by_name(param);
225 sysadm 1.29 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 sysadm 1.32
239 sysadm 1.34 int show_top10_menu(void *param)
240 sysadm 1.32 {
241 sysadm 1.35 static int show_top10 = 0;
242 sysadm 1.34 int ch = 0;
243    
244 sysadm 1.35 if (show_top10)
245     {
246     return NOREDRAW;
247     }
248     show_top10 = 1;
249 sysadm 1.38
250 sysadm 1.34 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 sysadm 1.38
261     if (ch != KEY_NULL && ch != KEY_TIMEOUT)
262     {
263     BBS_last_access_tm = time(NULL);
264     }
265    
266 sysadm 1.34 switch (ch)
267     {
268     case KEY_NULL: // broken pipe
269 sysadm 1.38 log_error("KEY_NULL\n");
270 sysadm 1.35 show_top10 = 0;
271 sysadm 1.34 return 0;
272     case KEY_TIMEOUT:
273 sysadm 1.46 if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
274 sysadm 1.34 {
275 sysadm 1.38 log_error("User input timeout\n");
276 sysadm 1.35 show_top10 = 0;
277 sysadm 1.34 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 sysadm 1.38
306 sysadm 1.35 show_top10 = 0;
307 sysadm 1.32 return REDRAW;
308     }
309    
310     int locate_article(void *param)
311     {
312 sysadm 1.34 char buf[MAX_MENUITEM_NAME_LENGTH];
313 sysadm 1.32 char *sname, *aid, *saveptr;
314    
315 sysadm 1.34 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 sysadm 1.32
321     if (sname == NULL || aid == NULL)
322     {
323 sysadm 1.34 log_error("top10_locate(%s) error: invalid parameter\n", param);
324 sysadm 1.32 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 sysadm 1.37 if (article_favor_display(&BBS_article_favor) < 0)
335     {
336     log_error("article_favor_display() error\n");
337     }
338 sysadm 1.32
339     return REDRAW;
340     }
341 sysadm 1.42
342 sysadm 1.43 int list_user(void *param)
343 sysadm 1.42 {
344 sysadm 1.43 if (user_list_display(0) < 0)
345 sysadm 1.42 {
346 sysadm 1.43 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 sysadm 1.42 }
358    
359     return REDRAW;
360     }
361 sysadm 1.47
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