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


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

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