/[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.41 - (hide 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 sysadm 1.1 /***************************************************************************
2 sysadm 1.6 menu_proc.c - description
3     -------------------
4 sysadm 1.11 Copyright : (C) 2004-2025 by Leaflet
5     Email : leaflet@leafok.com
6 sysadm 1.1 ***************************************************************************/
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 sysadm 1.11 * the Free Software Foundation; either version 3 of the License, or *
13 sysadm 1.1 * (at your option) any later version. *
14     * *
15     ***************************************************************************/
16    
17 sysadm 1.28 #include "article_cache.h"
18 sysadm 1.37 #include "article_favor_display.h"
19 sysadm 1.28 #include "article_view_log.h"
20 sysadm 1.1 #include "bbs.h"
21     #include "bbs_cmd.h"
22     #include "common.h"
23 sysadm 1.27 #include "io.h"
24 sysadm 1.7 #include "log.h"
25 sysadm 1.28 #include "login.h"
26 sysadm 1.27 #include "menu.h"
27     #include "section_list_display.h"
28 sysadm 1.7 #include "screen.h"
29 sysadm 1.20 #include "user_priv.h"
30 sysadm 1.1 #include <dlfcn.h>
31 sysadm 1.4 #include <errno.h>
32 sysadm 1.5 #include <signal.h>
33 sysadm 1.28 #include <stdlib.h>
34 sysadm 1.4 #include <string.h>
35 sysadm 1.1 #include <time.h>
36 sysadm 1.4 #include <unistd.h>
37 sysadm 1.25 #include <sys/types.h>
38 sysadm 1.1
39 sysadm 1.17 int list_section(void *param)
40     {
41 sysadm 1.31 section_list_display(param, 0);
42 sysadm 1.18
43     return REDRAW;
44 sysadm 1.17 }
45    
46 sysadm 1.41 typedef union exec_handler_t{
47     void *p;
48     int (*handler)();
49     } exec_handler;
50    
51 sysadm 1.16 int exec_mbem(void *param)
52 sysadm 1.1 {
53 sysadm 1.6 void *hdll;
54 sysadm 1.41 exec_handler func;
55 sysadm 1.6 char *c, *s;
56 sysadm 1.10 char buf[FILE_PATH_LEN];
57    
58 sysadm 1.16 strncpy(buf, (const char *)param, sizeof(buf) - 1);
59 sysadm 1.10 buf[sizeof(buf) - 1] = '\0';
60 sysadm 1.6
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 sysadm 1.41 if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
78     {
79     func.handler();
80     }
81 sysadm 1.6 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 sysadm 1.30 prints("加载库文件 [%s] 失败!!\r\n", s + 5);
93     prints("失败原因:%s\r\n", dlerror());
94 sysadm 1.6 press_any_key();
95     }
96     }
97    
98     return REDRAW;
99 sysadm 1.1 }
100    
101 sysadm 1.22 int exit_bbs(void *param)
102 sysadm 1.1 {
103 sysadm 1.6 return EXITBBS;
104 sysadm 1.1 }
105    
106 sysadm 1.16 int license(void *param)
107 sysadm 1.1 {
108 sysadm 1.24 display_file(DATA_LICENSE, 0);
109 sysadm 1.6
110     return REDRAW;
111 sysadm 1.1 }
112    
113 sysadm 1.16 int copyright(void *param)
114 sysadm 1.1 {
115 sysadm 1.24 display_file(DATA_COPYRIGHT, 1);
116 sysadm 1.1
117 sysadm 1.6 return REDRAW;
118 sysadm 1.3 }
119    
120 sysadm 1.40 int version(void *param)
121     {
122     display_file(DATA_VERSION, 1);
123    
124     return REDRAW;
125     }
126    
127 sysadm 1.22 int reload_bbs_conf(void *param)
128 sysadm 1.4 {
129 sysadm 1.12 clearscr();
130    
131 sysadm 1.15 if (kill(getppid(), SIGHUP) < 0)
132 sysadm 1.9 {
133 sysadm 1.15 log_error("Send SIGHUP signal failed (%d)\n", errno);
134 sysadm 1.12
135 sysadm 1.30 prints("发送指令失败\r\n");
136 sysadm 1.9 }
137 sysadm 1.12 else
138     {
139 sysadm 1.30 prints("已发送指令\r\n");
140 sysadm 1.12 }
141    
142     press_any_key();
143 sysadm 1.4
144 sysadm 1.6 return REDRAW;
145 sysadm 1.4 }
146    
147 sysadm 1.22 int shutdown_bbs(void *param)
148 sysadm 1.3 {
149 sysadm 1.23 log_common("Notify main process to exit\n");
150 sysadm 1.14
151     if (kill(getppid(), SIGTERM) < 0)
152 sysadm 1.9 {
153 sysadm 1.6 log_error("Send SIGTERM signal failed (%d)\n", errno);
154 sysadm 1.9 }
155 sysadm 1.3
156 sysadm 1.6 return REDRAW;
157 sysadm 1.1 }
158 sysadm 1.20
159 sysadm 1.33 int favor_section_filter(void *param)
160 sysadm 1.20 {
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 sysadm 1.28
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 sysadm 1.30 "| 返回[\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 sysadm 1.28 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 sysadm 1.29
225     int list_ex_section(void *param)
226     {
227     SECTION_LIST *p_section;
228    
229 sysadm 1.36 p_section = section_list_find_by_name(param);
230 sysadm 1.29 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 sysadm 1.32
244 sysadm 1.34 int show_top10_menu(void *param)
245 sysadm 1.32 {
246 sysadm 1.35 static int show_top10 = 0;
247 sysadm 1.34 int ch = 0;
248    
249 sysadm 1.35 if (show_top10)
250     {
251     return NOREDRAW;
252     }
253     show_top10 = 1;
254 sysadm 1.38
255 sysadm 1.34 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 sysadm 1.38
266     if (ch != KEY_NULL && ch != KEY_TIMEOUT)
267     {
268     BBS_last_access_tm = time(NULL);
269     }
270    
271 sysadm 1.34 switch (ch)
272     {
273     case KEY_NULL: // broken pipe
274 sysadm 1.38 log_error("KEY_NULL\n");
275 sysadm 1.35 show_top10 = 0;
276 sysadm 1.34 return 0;
277     case KEY_TIMEOUT:
278     if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
279     {
280 sysadm 1.38 log_error("User input timeout\n");
281 sysadm 1.35 show_top10 = 0;
282 sysadm 1.34 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 sysadm 1.38
311 sysadm 1.35 show_top10 = 0;
312 sysadm 1.32 return REDRAW;
313     }
314    
315     int locate_article(void *param)
316     {
317 sysadm 1.34 char buf[MAX_MENUITEM_NAME_LENGTH];
318 sysadm 1.32 char *sname, *aid, *saveptr;
319    
320 sysadm 1.34 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 sysadm 1.32
326     if (sname == NULL || aid == NULL)
327     {
328 sysadm 1.34 log_error("top10_locate(%s) error: invalid parameter\n", param);
329 sysadm 1.32 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 sysadm 1.37 if (article_favor_display(&BBS_article_favor) < 0)
340     {
341     log_error("article_favor_display() error\n");
342     }
343 sysadm 1.32
344     return REDRAW;
345     }

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