/[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.28 by sysadm, Tue Jun 24 10:01:24 2025 UTC Revision 1.61 by sysadm, Thu Dec 18 10:43:48 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
  *   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"
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 25  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 37  Line 39 
39    
40  int list_section(void *param)  int list_section(void *param)
41  {  {
42          section_list_display(param);          section_list_display(param, 0);
43    
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 62  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 81  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();                          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 95  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 109  int copyright(void *param) Line 146  int copyright(void *param)
146          return REDRAW;          return REDRAW;
147  }  }
148    
149    int version(void *param)
150    {
151            display_file(DATA_VERSION, 1);
152    
153            return REDRAW;
154    }
155    
156  int reload_bbs_conf(void *param)  int reload_bbs_conf(void *param)
157  {  {
158          clearscr();          clearscr();
# Line 117  int reload_bbs_conf(void *param) Line 161  int reload_bbs_conf(void *param)
161          {          {
162                  log_error("Send SIGHUP signal failed (%d)\n", errno);                  log_error("Send SIGHUP signal failed (%d)\n", errno);
163    
164                  prints("ָʧ\r\n");                  prints("发送指令失败\r\n");
165          }          }
166          else          else
167          {          {
168                  prints("ѷָ\r\n");                  prints("已发送指令\r\n");
169          }          }
170    
171          press_any_key();          press_any_key();
# Line 131  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]\n", BBS_username);
186    
187                    if (kill(getppid(), SIGTERM) < 0)
188                    {
189                            log_error("Send SIGTERM signal failed (%d)\n", errno);
190                    }
191          }          }
192    
193          return REDRAW;          return REDRAW;
194  }  }
195    
196  int favour_section_filter(void *param)  int favor_section_filter(void *param)
197  {  {
198          MENU_ITEM *p_menu_item = param;          MENU_ITEM *p_menu_item = param;
199    
# Line 154  static int display_ex_article_key_handle Line 206  static int display_ex_article_key_handle
206          {          {
207          case 0: // Set msg          case 0: // Set msg
208                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
209                                   "| [\033[32m\033[33m,\033[32mESC\033[33m] | "                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
210                                   "ƶ[\033[32m\033[33m/\033[32m\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "                                   "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
211                                   "[\033[32mh\033[33m] |");                                   "帮助[\033[32mh\033[33m] |");
212                  break;                  break;
213          }          }
214    
# Line 205  int view_ex_article(void *param) Line 257  int view_ex_article(void *param)
257          }          }
258    
259          return REDRAW;          return REDRAW;
260    }
261    
262    int list_ex_section(void *param)
263    {
264            SECTION_LIST *p_section;
265    
266            p_section = section_list_find_by_name(param);
267            if (p_section == NULL)
268            {
269                    log_error("Section %s not found\n", (const char *)param);
270                    return -1;
271            }
272    
273            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);
276            }
277    
278            return REDRAW;
279    }
280    
281    int show_top10_menu(void *param)
282    {
283            static int show_top10 = 0;
284            int ch = 0;
285            int loop;
286    
287            if (show_top10)
288            {
289                    return NOREDRAW;
290            }
291            show_top10 = 1;
292    
293            clearscr();
294            show_top("", BBS_name, "");
295            show_bottom("");
296    
297            if (display_menu(&top10_menu) == 0)
298            {
299                    for (loop = 1; !SYS_server_exit && loop;)
300                    {
301                            iflush();
302                            ch = igetch(100);
303    
304                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
305                            {
306                                    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\n");
312                            }
313    
314                            switch (ch)
315                            {
316                            case KEY_NULL: // broken pipe
317                                    log_debug("KEY_NULL\n");
318                                    loop = 0;
319                                    break;
320                            case KEY_TIMEOUT:
321                                    if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
322                                    {
323                                            log_debug("User input timeout\n");
324                                            loop = 0;
325                                            break;
326                                    }
327                                    continue;
328                            case CR:
329                            default:
330                                    switch (menu_control(&top10_menu, ch))
331                                    {
332                                    case EXITMENU:
333                                            loop = 0;
334                                            break;
335                                    case REDRAW:
336                                            clearscr();
337                                            show_bottom("");
338                                            display_menu(&top10_menu);
339                                            break;
340                                    case NOREDRAW:
341                                    case UNKNOWN_CMD:
342                                    default:
343                                            break;
344                                    }
345                            }
346                    }
347            }
348    
349            show_top10 = 0;
350            return REDRAW;
351    }
352    
353    int locate_article(void *param)
354    {
355            char buf[MAX_MENUITEM_NAME_LENGTH];
356            char *sname, *aid, *saveptr;
357    
358            strncpy(buf, param, sizeof(buf) - 1);
359            buf[sizeof(buf) - 1] = '\0';
360    
361            sname = strtok_r(buf, "|", &saveptr);
362            aid = strtok_r(NULL, "|", &saveptr);
363    
364            if (sname == NULL || aid == NULL)
365            {
366                    log_error("top10_locate(%s) error: invalid parameter\n", param);
367                    return NOREDRAW;
368            }
369    
370            section_list_display(sname, atoi(aid));
371    
372            return REDRAW;
373    }
374    
375    int favor_topic(void *param)
376    {
377            if (article_favor_display(&BBS_article_favor) < 0)
378            {
379                    log_error("article_favor_display() error\n");
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\n");
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\n");
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\n", 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\n", BBS_priv.uid);
420            }
421    
422            return REDRAW;
423  }  }


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

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