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


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

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