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