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

Diff of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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