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


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

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