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


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

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