/[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.5 by sysadm, Sat May 7 12:15:30 2005 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      begin                : Fri May 6 2005   *   - handler functions of menu commands
5      copyright            : (C) 2005 by Leaflet   *
6      email                : leaflet@leafok.com   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7   ***************************************************************************/   */
8    
9  /***************************************************************************  #include "article_cache.h"
10   *                                                                         *  #include "article_favor_display.h"
11   *   This program is free software; you can redistribute it and/or modify  *  #include "article_view_log.h"
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 2 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"
15  #include "io.h"  #include "io.h"
16    #include "log.h"
17    #include "login.h"
18    #include "menu.h"
19    #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)
33    {
34            section_list_display(param, 0);
35    
36            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)
46    {
47            void *hdll;
48            exec_handler func;
49            char *c, *s;
50            char buf[FILE_PATH_LEN];
51    
52            strncpy(buf, (const char *)param, sizeof(buf) - 1);
53            buf[sizeof(buf) - 1] = '\0';
54    
55            s = strstr(buf, "@mod:");
56            if (s)
57            {
58                    c = strstr(s + 5, "#");
59                    if (c)
60                    {
61                            *c = 0;
62                            c++;
63                    }
64    
65                    hdll = dlopen(s + 5, RTLD_LAZY);
66    
67                    if (hdll)
68                    {
69                            char *error;
70    
71                            if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
72                            {
73                                    func.handler();
74                            }
75                            else if ((error = dlerror()) != NULL)
76                            {
77                                    clearscr();
78                                    prints("%s\r\n", error);
79                                    press_any_key();
80                            }
81                            dlclose(hdll);
82                    }
83                    else
84                    {
85                            clearscr();
86                            prints("加载库文件 [%s] 失败!!\r\n", s + 5);
87                            prints("失败原因:%s\r\n", dlerror());
88                            press_any_key();
89                    }
90            }
91    
92            return REDRAW;
93    }
94    
95    int exit_bbs(void *param)
96    {
97            return EXITBBS;
98    }
99    
100    int license(void *param)
101    {
102            display_file(DATA_LICENSE, 0);
103    
104            return REDRAW;
105    }
106    
107    int copyright(void *param)
108    {
109            display_file(DATA_COPYRIGHT, 1);
110    
111            return REDRAW;
112    }
113    
114    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();
124    
125            if (kill(getppid(), SIGHUP) < 0)
126            {
127                    log_error("Send SIGHUP signal failed (%d)\n", errno);
128    
129                    prints("发送指令失败\r\n");
130            }
131            else
132            {
133                    prints("已发送指令\r\n");
134            }
135    
136            press_any_key();
137    
138            return REDRAW;
139    }
140    
141  int  int shutdown_bbs(void *param)
 exec_mbem(const char *str)  
142  {  {
143      void *hdll;          log_common("Notify main process to exit\n");
     int (*func) ();  
     char *c,*s;  
     char buf[1024];  
144    
145      strcpy(buf, str);          if (kill(getppid(), SIGTERM) < 0)
146      s = strstr(buf, "@mod:");          {
147      if (s) {                  log_error("Send SIGTERM signal failed (%d)\n", errno);
148          c = strstr(s + 5, "#");          }
         if (c) {  
             *c = 0;  
             c++;  
         }  
149    
150          hdll = dlopen (s + 5, RTLD_LAZY);          return REDRAW;
151    }
152    
153          if (hdll) {  int favor_section_filter(void *param)
154              char *error;  {
155            MENU_ITEM *p_menu_item = param;
156    
157              if ((func = dlsym (hdll, c ? c : "mod_main")) != NULL)          return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));
158                  func ();  }
             else if ((error = dlerror ()) != NULL) {  
                 clearscr ();  
                 prints ("%s\r\n", error);  
                 press_any_key ();  
             }  
             dlclose (hdll);  
         } else {  
             clearscr ();  
             prints ("ؿļ [%s] ʧ!!\r\n", s + 5);  
             prints ("ʧԭ:%s\r\n", dlerror());  
             press_any_key ();  
         }  
     }  
159    
160          return REDRAW;  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  int view_ex_article(void *param)
 exitbbs (const char *s)  
176  {  {
177          return EXITBBS;          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  int list_ex_section(void *param)
 license (const char *s)  
220  {  {
221          char temp[256];          SECTION_LIST *p_section;
222            
223      strcpy (temp, app_home_dir);          p_section = section_list_find_by_name(param);
224      strcat (temp, "data/license.txt");          if (p_section == NULL)
225      display_file_ex (temp, 0, 1);          {
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;          return REDRAW;
329  }  }
330    
331  int  int favor_topic(void *param)
 copyright (const char *s)  
332  {  {
333      char temp[256];          if (article_favor_display(&BBS_article_favor) < 0)
334                    {
335      strcpy (temp, app_home_dir);                  log_error("article_favor_display() error\n");
336      strcat (temp, "data/copyright.txt");          }
     display_file_ex (temp, 0, 1);  
337    
338      return REDRAW;          return REDRAW;
339  }  }
340    
341  int  int list_user(void *param)
 reloadbbsmenu (const char *s)  
342  {  {
343      if (kill (getppid (), SIG_RELOAD_MENU) < 0)          if (user_list_display(0) < 0)
344        log_error ("Send SIG_RELOAD_MENU signal failed (%d)\n", errno);          {
345                    log_error("user_list_display(all_user) error\n");
346            }
347    
348      return REDRAW;          return REDRAW;
349  }  }
350    
351  int  int list_online_user(void *param)
 shutdownbbs (const char *s)  
352  {  {
353      if (kill (0, SIGTERM) < 0)          if (user_list_display(1) < 0)
354        log_error ("Send SIGTERM signal failed (%d)\n", errno);          {
355                    log_error("user_list_display(online_user) error\n");
356            }
357    
358      return REDRAW;          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