/[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.37 by sysadm, Tue Oct 14 06:27:44 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            menu_proc.c  -  description                                                    menu_proc.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Fri May 6 2005          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2005 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "article_cache.h"
18    #include "article_favor_display.h"
19    #include "article_view_log.h"
20  #include "bbs.h"  #include "bbs.h"
21  #include "bbs_cmd.h"  #include "bbs_cmd.h"
22  #include "common.h"  #include "common.h"
23  #include "io.h"  #include "io.h"
24    #include "log.h"
25    #include "login.h"
26    #include "menu.h"
27    #include "section_list_display.h"
28    #include "screen.h"
29    #include "user_priv.h"
30  #include <dlfcn.h>  #include <dlfcn.h>
31  #include <errno.h>  #include <errno.h>
32  #include <signal.h>  #include <signal.h>
33    #include <stdlib.h>
34  #include <string.h>  #include <string.h>
 #include <sys/types.h>  
35  #include <time.h>  #include <time.h>
36  #include <unistd.h>  #include <unistd.h>
37    #include <sys/types.h>
38    
39  int  int list_section(void *param)
 exec_mbem(const char *str)  
40  {  {
41      void *hdll;          section_list_display(param, 0);
42      int (*func) ();  
43      char *c,*s;          return REDRAW;
44      char buf[1024];  }
45    
46      strcpy(buf, str);  int exec_mbem(void *param)
     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)  
47  {  {
48          return EXITBBS;          void *hdll;
49            int (*func)();
50            char *c, *s;
51            char buf[FILE_PATH_LEN];
52    
53            strncpy(buf, (const char *)param, sizeof(buf) - 1);
54            buf[sizeof(buf) - 1] = '\0';
55    
56            s = strstr(buf, "@mod:");
57            if (s)
58            {
59                    c = strstr(s + 5, "#");
60                    if (c)
61                    {
62                            *c = 0;
63                            c++;
64                    }
65    
66                    hdll = dlopen(s + 5, RTLD_LAZY);
67    
68                    if (hdll)
69                    {
70                            char *error;
71    
72                            if ((func = dlsym(hdll, c ? c : "mod_main")) != NULL)
73                                    func();
74                            else if ((error = dlerror()) != NULL)
75                            {
76                                    clearscr();
77                                    prints("%s\r\n", error);
78                                    press_any_key();
79                            }
80                            dlclose(hdll);
81                    }
82                    else
83                    {
84                            clearscr();
85                            prints("鍔犺浇搴撴枃浠 [%s] 澶辫触!!\r\n", s + 5);
86                            prints("澶辫触鍘熷洜:%s\r\n", dlerror());
87                            press_any_key();
88                    }
89            }
90    
91            return REDRAW;
92  }  }
93    
94  int  int exit_bbs(void *param)
 license (const char *s)  
95  {  {
96          char temp[256];          return EXITBBS;
97            }
98      strcpy (temp, app_home_dir);  
99      strcat (temp, "data/license.txt");  int license(void *param)
100      display_file_ex (temp, 0, 1);  {
101            display_file(DATA_LICENSE, 0);
102    
103          return REDRAW;          return REDRAW;
104  }  }
105    
106  int  int copyright(void *param)
 copyright (const char *s)  
107  {  {
108      char temp[256];          display_file(DATA_COPYRIGHT, 1);
           
     strcpy (temp, app_home_dir);  
     strcat (temp, "data/copyright.txt");  
     display_file_ex (temp, 0, 1);  
109    
110      return REDRAW;          return REDRAW;
111  }  }
112    
113  int  int reload_bbs_conf(void *param)
 reloadbbsmenu (const char *s)  
114  {  {
115      if (kill (getppid (), SIG_RELOAD_MENU) < 0)          clearscr();
116        log_error ("Send SIG_RELOAD_MENU signal failed (%d)\n", errno);  
117            if (kill(getppid(), SIGHUP) < 0)
118            {
119                    log_error("Send SIGHUP signal failed (%d)\n", errno);
120    
121                    prints("鍙戦佹寚浠ゅけ璐r\n");
122            }
123            else
124            {
125                    prints("宸插彂閫佹寚浠r\n");
126            }
127    
128            press_any_key();
129    
130            return REDRAW;
131    }
132    
133    int shutdown_bbs(void *param)
134    {
135            log_common("Notify main process to exit\n");
136    
137            if (kill(getppid(), SIGTERM) < 0)
138            {
139                    log_error("Send SIGTERM signal failed (%d)\n", errno);
140            }
141    
142            return REDRAW;
143    }
144    
145    int favor_section_filter(void *param)
146    {
147            MENU_ITEM *p_menu_item = param;
148    
149            return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));
150    }
151    
152    static int display_ex_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
153    {
154            switch (*p_key)
155            {
156            case 0: // Set msg
157                    snprintf(p_ctx->msg, sizeof(p_ctx->msg),
158                                     "| 杩斿洖[\033[32m鈫怽033[33m,\033[32mESC\033[33m] | "
159                                     "绉诲姩[\033[32m鈫慭033[33m/\033[32m鈫揬033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
160                                     "甯姪[\033[32mh\033[33m] |");
161                    break;
162            }
163    
164            return 0;
165    }
166    
167    int view_ex_article(void *param)
168    {
169            ARTICLE_CACHE cache;
170            ARTICLE *p_article;
171            int32_t aid = atoi(param);
172            int ret;
173    
174            (void)ret;
175    
176            p_article = article_block_find_by_aid(aid);
177            if (p_article == NULL)
178            {
179                    log_error("article_block_find_by_aid(%d) error\n", aid);
180                    return NOREDRAW;
181            }
182    
183            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
184            {
185                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
186                    return NOREDRAW;
187            }
188    
189            if (user_online_update("VIEW_ARTICLE") < 0)
190            {
191                    log_error("user_online_update(VIEW_ARTICLE) error\n");
192            }
193    
194            ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
195                                               display_ex_article_key_handler, DATA_READ_HELP);
196    
197            if (article_cache_unload(&cache) < 0)
198            {
199                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
200            }
201    
202            // Update article_view_log
203            if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)
204            {
205                    log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid);
206            }
207    
208            return REDRAW;
209    }
210    
211    int list_ex_section(void *param)
212    {
213            SECTION_LIST *p_section;
214    
215            p_section = section_list_find_by_name(param);
216            if (p_section == NULL)
217            {
218                    log_error("Section %s not found\n", (const char *)param);
219                    return -1;
220            }
221    
222            if (section_list_ex_dir_display(p_section) < 0)
223            {
224                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
225            }
226    
227            return REDRAW;
228    }
229    
230    int show_top10_menu(void *param)
231    {
232            static int show_top10 = 0;
233            int ch = 0;
234    
235            if (show_top10)
236            {
237                    return NOREDRAW;
238            }
239            show_top10 = 1;
240            
241            clearscr();
242            show_top("", BBS_name, "");
243            show_bottom("");
244    
245            if (display_menu(&top10_menu) == 0)
246            {
247                    while (!SYS_server_exit)
248                    {
249                            iflush();
250                            ch = igetch(100);
251                            switch (ch)
252                            {
253                            case KEY_NULL: // broken pipe
254                                    show_top10 = 0;
255                                    return 0;
256                            case KEY_TIMEOUT:
257                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
258                                    {
259                                            show_top10 = 0;
260                                            return 0;
261                                    }
262                                    continue;
263                            case CR:
264                                    igetch_reset();
265                            default:
266                                    switch (menu_control(&top10_menu, ch))
267                                    {
268                                    case EXITMENU:
269                                            ch = EXITMENU;
270                                            break;
271                                    case REDRAW:
272                                            clearscr();
273                                            show_bottom("");
274                                            display_menu(&top10_menu);
275                                            break;
276                                    case NOREDRAW:
277                                    case UNKNOWN_CMD:
278                                    default:
279                                            break;
280                                    }
281                            }
282    
283                            BBS_last_access_tm = time(NULL);
284    
285                            if (ch == EXITMENU)
286                            {
287                                    break;
288                            }
289                    }
290            }
291            
292            show_top10 = 0;
293            return REDRAW;
294    }
295    
296    int locate_article(void *param)
297    {
298            char buf[MAX_MENUITEM_NAME_LENGTH];
299            char *sname, *aid, *saveptr;
300    
301            strncpy(buf, param, sizeof(buf) - 1);
302            buf[sizeof(buf) - 1] = '\0';
303    
304            sname = strtok_r(buf, "|", &saveptr);
305            aid = strtok_r(NULL, "|", &saveptr);
306    
307            if (sname == NULL || aid == NULL)
308            {
309                    log_error("top10_locate(%s) error: invalid parameter\n", param);
310                    return NOREDRAW;
311            }
312    
313            section_list_display(sname, atoi(aid));
314    
315      return REDRAW;          return REDRAW;
316  }  }
317    
318  int  int favor_topic(void *param)
 shutdownbbs (const char *s)  
319  {  {
320      if (kill (0, SIGTERM) < 0)          if (article_favor_display(&BBS_article_favor) < 0)
321        log_error ("Send SIGTERM signal failed (%d)\n", errno);          {
322                    log_error("article_favor_display() error\n");
323            }
324    
325      return REDRAW;          return REDRAW;
326  }  }


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

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