/[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.40 by sysadm, Fri Oct 17 12:23:01 2025 UTC Revision 1.63 by sysadm, Sat Jan 3 10:27:14 2026 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-2026  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
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "article_favor_display.h"  #include "article_favor_display.h"
15  #include "article_view_log.h"  #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"
21  #include "io.h"  #include "io.h"
22  #include "log.h"  #include "log.h"
# Line 26  Line 24 
24  #include "menu.h"  #include "menu.h"
25  #include "section_list_display.h"  #include "section_list_display.h"
26  #include "screen.h"  #include "screen.h"
27    #include "user_info_update.h"
28    #include "user_list_display.h"
29  #include "user_priv.h"  #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>
# Line 43  int list_section(void *param) Line 44  int list_section(void *param)
44          return REDRAW;          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 63  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 86  int exec_mbem(void *param) Line 96  int exec_mbem(void *param)
96                          prints("失败原因:%s\r\n", dlerror());                          prints("失败原因:%s\r\n", dlerror());
97                          press_any_key();                          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();
116                    }
117    #endif
118          }          }
119    
120          return REDRAW;          return REDRAW;
# Line 96  int exit_bbs(void *param) Line 125  int exit_bbs(void *param)
125          return EXITBBS;          return EXITBBS;
126  }  }
127    
128    int eula(void *param)
129    {
130            display_file(DATA_EULA, 0);
131    
132            return REDRAW;
133    }
134    
135  int license(void *param)  int license(void *param)
136  {  {
137          display_file(DATA_LICENSE, 0);          display_file(DATA_LICENSE, 0);
# Line 123  int reload_bbs_conf(void *param) Line 159  int reload_bbs_conf(void *param)
159    
160          if (kill(getppid(), SIGHUP) < 0)          if (kill(getppid(), SIGHUP) < 0)
161          {          {
162                  log_error("Send SIGHUP signal failed (%d)\n", errno);                  log_error("Send SIGHUP signal failed (%d)", errno);
163    
164                  prints("发送指令失败\r\n");                  prints("发送指令失败\r\n");
165          }          }
# Line 139  int reload_bbs_conf(void *param) Line 175  int reload_bbs_conf(void *param)
175    
176  int shutdown_bbs(void *param)  int shutdown_bbs(void *param)
177  {  {
178          log_common("Notify main process to exit\n");          char buf[2] = "N";
179    
180            clearscr();
181            get_data(1, 1, "真的要关闭系统吗[y/N]? ", buf, sizeof(buf), 1);
182    
183          if (kill(getppid(), SIGTERM) < 0)          if (toupper(buf[0]) == 'Y')
184          {          {
185                  log_error("Send SIGTERM signal failed (%d)\n", errno);                  log_common("Notify main process to exit by [%s]", BBS_username);
186    
187                    if (kill(getppid(), SIGTERM) < 0)
188                    {
189                            log_error("Send SIGTERM signal failed (%d)", errno);
190                    }
191          }          }
192    
193          return REDRAW;          return REDRAW;
# Line 183  int view_ex_article(void *param) Line 227  int view_ex_article(void *param)
227          p_article = article_block_find_by_aid(aid);          p_article = article_block_find_by_aid(aid);
228          if (p_article == NULL)          if (p_article == NULL)
229          {          {
230                  log_error("article_block_find_by_aid(%d) error\n", aid);                  log_error("article_block_find_by_aid(%d) error", aid);
231                  return NOREDRAW;                  return NOREDRAW;
232          }          }
233    
234          if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)          if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
235          {          {
236                  log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                  log_error("article_cache_load(aid=%d, cid=%d) error", p_article->aid, p_article->cid);
237                  return NOREDRAW;                  return NOREDRAW;
238          }          }
239    
240          if (user_online_update("VIEW_ARTICLE") < 0)          if (user_online_update("VIEW_ARTICLE") < 0)
241          {          {
242                  log_error("user_online_update(VIEW_ARTICLE) error\n");                  log_error("user_online_update(VIEW_ARTICLE) error");
243          }          }
244    
245          ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,          ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
# Line 203  int view_ex_article(void *param) Line 247  int view_ex_article(void *param)
247    
248          if (article_cache_unload(&cache) < 0)          if (article_cache_unload(&cache) < 0)
249          {          {
250                  log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                  log_error("article_cache_unload(aid=%d, cid=%d) error", p_article->aid, p_article->cid);
251          }          }
252    
253          // Update article_view_log          // Update article_view_log
254          if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)          if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)
255          {          {
256                  log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid);                  log_error("article_view_log_set_viewed(aid=%d) error", p_article->aid);
257          }          }
258    
259          return REDRAW;          return REDRAW;
# Line 222  int list_ex_section(void *param) Line 266  int list_ex_section(void *param)
266          p_section = section_list_find_by_name(param);          p_section = section_list_find_by_name(param);
267          if (p_section == NULL)          if (p_section == NULL)
268          {          {
269                  log_error("Section %s not found\n", (const char *)param);                  log_error("Section %s not found", (const char *)param);
270                  return -1;                  return -1;
271          }          }
272    
273          if (section_list_ex_dir_display(p_section) < 0)          if (section_list_ex_dir_display(p_section) < 0)
274          {          {
275                  log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);                  log_error("section_list_ex_dir_display(sid=%d) error", p_section->sid);
276          }          }
277    
278          return REDRAW;          return REDRAW;
# Line 238  int show_top10_menu(void *param) Line 282  int show_top10_menu(void *param)
282  {  {
283          static int show_top10 = 0;          static int show_top10 = 0;
284          int ch = 0;          int ch = 0;
285            int loop;
286    
287          if (show_top10)          if (show_top10)
288          {          {
# Line 251  int show_top10_menu(void *param) Line 296  int show_top10_menu(void *param)
296    
297          if (display_menu(&top10_menu) == 0)          if (display_menu(&top10_menu) == 0)
298          {          {
299                  while (!SYS_server_exit)                  for (loop = 1; !SYS_server_exit && loop;)
300                  {                  {
301                          iflush();                          iflush();
302                          ch = igetch(100);                          ch = igetch(100);
# Line 261  int show_top10_menu(void *param) Line 306  int show_top10_menu(void *param)
306                                  BBS_last_access_tm = time(NULL);                                  BBS_last_access_tm = time(NULL);
307                          }                          }
308    
309                            if (user_online_update("TOP10_MENU") < 0)
310                            {
311                                    log_error("user_online_update(TOP10_MENU) error");
312                            }
313    
314                          switch (ch)                          switch (ch)
315                          {                          {
316                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
317                                  log_error("KEY_NULL\n");                                  log_debug("KEY_NULL");
318                                  show_top10 = 0;                                  loop = 0;
319                                  return 0;                                  break;
320                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
321                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
322                                  {                                  {
323                                          log_error("User input timeout\n");                                          log_debug("User input timeout");
324                                          show_top10 = 0;                                          loop = 0;
325                                          return 0;                                          break;
326                                  }                                  }
327                                  continue;                                  continue;
328                          case CR:                          case CR:
# Line 280  int show_top10_menu(void *param) Line 330  int show_top10_menu(void *param)
330                                  switch (menu_control(&top10_menu, ch))                                  switch (menu_control(&top10_menu, ch))
331                                  {                                  {
332                                  case EXITMENU:                                  case EXITMENU:
333                                          ch = EXITMENU;                                          loop = 0;
334                                          break;                                          break;
335                                  case REDRAW:                                  case REDRAW:
336                                          clearscr();                                          clearscr();
# Line 293  int show_top10_menu(void *param) Line 343  int show_top10_menu(void *param)
343                                          break;                                          break;
344                                  }                                  }
345                          }                          }
   
                         if (ch == EXITMENU)  
                         {  
                                 break;  
                         }  
346                  }                  }
347          }          }
348    
# Line 318  int locate_article(void *param) Line 363  int locate_article(void *param)
363    
364          if (sname == NULL || aid == NULL)          if (sname == NULL || aid == NULL)
365          {          {
366                  log_error("top10_locate(%s) error: invalid parameter\n", param);                  log_error("top10_locate(%s) error: invalid parameter", param);
367                  return NOREDRAW;                  return NOREDRAW;
368          }          }
369    
# Line 331  int favor_topic(void *param) Line 376  int favor_topic(void *param)
376  {  {
377          if (article_favor_display(&BBS_article_favor) < 0)          if (article_favor_display(&BBS_article_favor) < 0)
378          {          {
379                  log_error("article_favor_display() error\n");                  log_error("article_favor_display() error");
380            }
381    
382            return REDRAW;
383    }
384    
385    int list_user(void *param)
386    {
387            if (user_list_display(0) < 0)
388            {
389                    log_error("user_list_display(all_user) error");
390            }
391    
392            return REDRAW;
393    }
394    
395    int list_online_user(void *param)
396    {
397            if (user_list_display(1) < 0)
398            {
399                    log_error("user_list_display(online_user) error");
400            }
401    
402            return REDRAW;
403    }
404    
405    int edit_intro(void *param)
406    {
407            if (user_intro_edit(BBS_priv.uid) < 0)
408            {
409                    log_error("user_intro_edit(%d) error", BBS_priv.uid);
410            }
411    
412            return REDRAW;
413    }
414    
415    int edit_sign(void *param)
416    {
417            if (user_sign_edit(BBS_priv.uid) < 0)
418            {
419                    log_error("user_sign_edit(%d) error", BBS_priv.uid);
420          }          }
421    
422          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