/[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.33 by sysadm, Mon Oct 13 05:39:45 2025 UTC Revision 1.49 by sysadm, Fri Nov 7 12:02:25 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     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "article_cache.h"  #include "article_cache.h"
10    #include "article_favor_display.h"
11  #include "article_view_log.h"  #include "article_view_log.h"
12  #include "bbs.h"  #include "bbs.h"
13  #include "bbs_cmd.h"  #include "bbs_cmd.h"
# Line 25  Line 18 
18  #include "menu.h"  #include "menu.h"
19  #include "section_list_display.h"  #include "section_list_display.h"
20  #include "screen.h"  #include "screen.h"
21    #include "user_info_update.h"
22    #include "user_list_display.h"
23  #include "user_priv.h"  #include "user_priv.h"
24    #include <ctype.h>
25  #include <dlfcn.h>  #include <dlfcn.h>
26  #include <errno.h>  #include <errno.h>
27  #include <signal.h>  #include <signal.h>
# Line 42  int list_section(void *param) Line 38  int list_section(void *param)
38          return REDRAW;          return REDRAW;
39  }  }
40    
41    typedef union exec_handler_t
42    {
43            void *p;
44            int (*handler)();
45    } exec_handler;
46    
47  int exec_mbem(void *param)  int exec_mbem(void *param)
48  {  {
49          void *hdll;          void *hdll;
50          int (*func)();          exec_handler func;
51          char *c, *s;          char *c, *s;
52          char buf[FILE_PATH_LEN];          char buf[FILE_PATH_LEN];
53    
# Line 68  int exec_mbem(void *param) Line 70  int exec_mbem(void *param)
70                  {                  {
71                          char *error;                          char *error;
72    
73                          if ((func = dlsym(hdll, c ? c : "mod_main")) != NULL)                          if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
74                                  func();                          {
75                                    func.handler();
76                            }
77                          else if ((error = dlerror()) != NULL)                          else if ((error = dlerror()) != NULL)
78                          {                          {
79                                  clearscr();                                  clearscr();
# Line 109  int copyright(void *param) Line 113  int copyright(void *param)
113          return REDRAW;          return REDRAW;
114  }  }
115    
116    int version(void *param)
117    {
118            display_file(DATA_VERSION, 1);
119    
120            return REDRAW;
121    }
122    
123  int reload_bbs_conf(void *param)  int reload_bbs_conf(void *param)
124  {  {
125          clearscr();          clearscr();
# Line 131  int reload_bbs_conf(void *param) Line 142  int reload_bbs_conf(void *param)
142    
143  int shutdown_bbs(void *param)  int shutdown_bbs(void *param)
144  {  {
145          log_common("Notify main process to exit\n");          char buf[2] = "N";
146    
147            clearscr();
148            get_data(1, 1, "真的要关闭系统吗[y/N]? ", buf, sizeof(buf), 1);
149    
150          if (kill(getppid(), SIGTERM) < 0)          if (toupper(buf[0]) == 'Y')
151          {          {
152                  log_error("Send SIGTERM signal failed (%d)\n", errno);                  log_common("Notify main process to exit by [%s]\n", BBS_username);
153    
154                    if (kill(getppid(), SIGTERM) < 0)
155                    {
156                            log_error("Send SIGTERM signal failed (%d)\n", errno);
157                    }
158          }          }
159    
160          return REDRAW;          return REDRAW;
# Line 211  int list_ex_section(void *param) Line 230  int list_ex_section(void *param)
230  {  {
231          SECTION_LIST *p_section;          SECTION_LIST *p_section;
232    
233          p_section = section_list_find_by_name(param, NULL);          p_section = section_list_find_by_name(param);
234          if (p_section == NULL)          if (p_section == NULL)
235          {          {
236                  log_error("Section %s not found\n", (const char *)param);                  log_error("Section %s not found\n", (const char *)param);
# Line 226  int list_ex_section(void *param) Line 245  int list_ex_section(void *param)
245          return REDRAW;          return REDRAW;
246  }  }
247    
248  int top10_menu(void *param)  int show_top10_menu(void *param)
249  {  {
250            static int show_top10 = 0;
251            int ch = 0;
252    
253            if (show_top10)
254            {
255                    return NOREDRAW;
256            }
257            show_top10 = 1;
258    
259            clearscr();
260            show_top("", BBS_name, "");
261            show_bottom("");
262    
263            if (display_menu(&top10_menu) == 0)
264            {
265                    while (!SYS_server_exit)
266                    {
267                            iflush();
268                            ch = igetch(100);
269    
270                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
271                            {
272                                    BBS_last_access_tm = time(NULL);
273                            }
274    
275                            switch (ch)
276                            {
277                            case KEY_NULL: // broken pipe
278                                    log_error("KEY_NULL\n");
279                                    show_top10 = 0;
280                                    return 0;
281                            case KEY_TIMEOUT:
282                                    if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
283                                    {
284                                            log_error("User input timeout\n");
285                                            show_top10 = 0;
286                                            return 0;
287                                    }
288                                    continue;
289                            case CR:
290                            default:
291                                    switch (menu_control(&top10_menu, ch))
292                                    {
293                                    case EXITMENU:
294                                            ch = EXITMENU;
295                                            break;
296                                    case REDRAW:
297                                            clearscr();
298                                            show_bottom("");
299                                            display_menu(&top10_menu);
300                                            break;
301                                    case NOREDRAW:
302                                    case UNKNOWN_CMD:
303                                    default:
304                                            break;
305                                    }
306                            }
307    
308                            if (ch == EXITMENU)
309                            {
310                                    break;
311                            }
312                    }
313            }
314    
315            show_top10 = 0;
316          return REDRAW;          return REDRAW;
317  }  }
318    
319  int locate_article(void *param)  int locate_article(void *param)
320  {  {
321            char buf[MAX_MENUITEM_NAME_LENGTH];
322          char *sname, *aid, *saveptr;          char *sname, *aid, *saveptr;
323    
324          sname = strtok_r(param, " ", &saveptr);          strncpy(buf, param, sizeof(buf) - 1);
325          aid = strtok_r(NULL, " ", &saveptr);          buf[sizeof(buf) - 1] = '\0';
326    
327            sname = strtok_r(buf, "|", &saveptr);
328            aid = strtok_r(NULL, "|", &saveptr);
329    
330          if (sname == NULL || aid == NULL)          if (sname == NULL || aid == NULL)
331          {          {
332                  log_error("top10_locate() error: invalid parameter\n", (const char *)param);                  log_error("top10_locate(%s) error: invalid parameter\n", param);
333                  return NOREDRAW;                  return NOREDRAW;
334          }          }
335    
# Line 251  int locate_article(void *param) Line 340  int locate_article(void *param)
340    
341  int favor_topic(void *param)  int favor_topic(void *param)
342  {  {
343          clearscr();          if (article_favor_display(&BBS_article_favor) < 0)
344          prints("此功能尚未实现");          {
345          press_any_key();                  log_error("article_favor_display() error\n");
346            }
347    
348            return REDRAW;
349    }
350    
351    int list_user(void *param)
352    {
353            if (user_list_display(0) < 0)
354            {
355                    log_error("user_list_display(all_user) error\n");
356            }
357    
358            return REDRAW;
359    }
360    
361    int list_online_user(void *param)
362    {
363            if (user_list_display(1) < 0)
364            {
365                    log_error("user_list_display(online_user) error\n");
366            }
367    
368            return REDRAW;
369    }
370    
371    int edit_intro(void *param)
372    {
373            if (user_intro_edit(BBS_priv.uid) < 0)
374            {
375                    log_error("user_intro_edit(%d) error\n", BBS_priv.uid);
376            }
377    
378          return REDRAW;          return REDRAW;
379  }  }


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

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