/[LeafOK_CVS]/lbbs/src/section_list_display.c
ViewVC logotype

Diff of /lbbs/src/section_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.61 by sysadm, Sun Nov 2 14:38:53 2025 UTC Revision 1.85 by sysadm, Thu Dec 25 14:37:08 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          section_list_display.c  -  description  /*
3                                                           -------------------   * section_list_display
4          Copyright            : (C) 2004-2025 by Leaflet   *   - user interactive feature of section articles list
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "article_favor.h"  #include "article_favor.h"
# Line 31  Line 27 
27  #include "screen.h"  #include "screen.h"
28  #include "str_process.h"  #include "str_process.h"
29  #include "user_info_display.h"  #include "user_info_display.h"
30    #include "user_list_display.h"
31  #include "user_priv.h"  #include "user_priv.h"
32    #include <ctype.h>
33  #include <errno.h>  #include <errno.h>
34  #include <string.h>  #include <string.h>
35  #include <time.h>  #include <time.h>
36  #include <sys/param.h>  #include <sys/param.h>
37    
38    enum _section_list_display_constant_t
39    {
40            TITLE_SEARCH_MAX_LEN = 60,
41    };
42    
43  static int32_t section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
44  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
45  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
# Line 55  enum select_cmd_t Line 58  enum select_cmd_t
58          QUERY_USER,          QUERY_USER,
59          SET_FAVOR_ARTICLE,          SET_FAVOR_ARTICLE,
60          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
61            SET_EXCERPTION_ARTICLE,
62          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
63          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
64            LAST_SECTION_ARTICLE,
65          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
66            SCAN_ARTICLE_BACKWARD_BY_USER,
67            SCAN_ARTICLE_FORWARD_BY_USER,
68            SCAN_ARTICLE_BACKWARD_BY_TITLE,
69            SCAN_ARTICLE_FORWARD_BY_TITLE,
70          VIEW_EX_DIR,          VIEW_EX_DIR,
71          SHOW_TOP10,          SHOW_TOP10,
72            SEARCH_USER,
73  };  };
74    
75  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)  static int section_list_draw_items(int page_id, const ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
76  {  {
77          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
78          struct tm tm_sub;          struct tm tm_sub;
# Line 92  static int section_list_draw_items(int p Line 102  static int section_list_draw_items(int p
102                          is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log);                          is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log);
103                          if (is_viewed < 0)                          if (is_viewed < 0)
104                          {                          {
105                                  log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid);                                  log_error("article_view_log_is_viewed(aid=%d) error", p_articles[i]->aid);
106                                  is_viewed = 0;                                  is_viewed = 0;
107                          }                          }
108                  }                  }
# Line 102  static int section_list_draw_items(int p Line 112  static int section_list_draw_items(int p
112                          is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);                          is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
113                          if (is_favor < 0)                          if (is_favor < 0)
114                          {                          {
115                                  log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);                                  log_error("article_favor_check(aid=%d) error", p_articles[i]->aid);
116                                  is_favor = 0;                                  is_favor = 0;
117                          }                          }
118                  }                  }
# Line 216  static int section_list_draw_screen(cons Line 226  static int section_list_draw_screen(cons
226    
227          if (master_list[0] != '\0')          if (master_list[0] != '\0')
228          {          {
229                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主: %s", master_list);
230          }          }
231          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
232    
# Line 261  static enum select_cmd_t section_list_se Line 271  static enum select_cmd_t section_list_se
271                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
272                  {                  {
273                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
274    
275                            // Refresh current action
276                            if (user_online_update(NULL) < 0)
277                            {
278                                    log_error("user_online_update(NULL) error");
279                            }
280                  }                  }
281    
282                  switch (ch)                  switch (ch)
283                  {                  {
284                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
285                          log_error("KEY_NULL\n");                          log_debug("KEY_NULL");
286                          return EXIT_SECTION;                          return EXIT_SECTION;
287                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
288                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
289                          {                          {
290                                  log_error("User input timeout\n");                                  log_debug("User input timeout");
291                                  return EXIT_SECTION;                                  return EXIT_SECTION;
292                          }                          }
293                          continue;                          continue;
# Line 326  static enum select_cmd_t section_list_se Line 342  static enum select_cmd_t section_list_se
342                                  return UNSET_FAVOR_ARTICLE;                                  return UNSET_FAVOR_ARTICLE;
343                          }                          }
344                          break;                          break;
345                    case 'm':
346                            if (item_count > 0)
347                            {
348                                    return SET_EXCERPTION_ARTICLE;
349                            }
350                            break;
351                  case KEY_HOME:                  case KEY_HOME:
352                          *p_page_id = 0;                          *p_page_id = 0;
353                  case 'P':                  case 'P':
# Line 359  static enum select_cmd_t section_list_se Line 381  static enum select_cmd_t section_list_se
381                          break;                          break;
382                  case '$':                  case '$':
383                  case KEY_END:                  case KEY_END:
384                            if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list
385                            {
386                                    return LAST_SECTION_ARTICLE;
387                            }
388                          if (total_page > 0)                          if (total_page > 0)
389                          {                          {
390                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
# Line 407  static enum select_cmd_t section_list_se Line 433  static enum select_cmd_t section_list_se
433                                  return SCAN_NEW_ARTICLE;                                  return SCAN_NEW_ARTICLE;
434                          }                          }
435                          break;                          break;
436                    case 'A':
437                            if (item_count > 0)
438                            {
439                                    return SCAN_ARTICLE_BACKWARD_BY_USER;
440                            }
441                            break;
442                    case 'a':
443                            if (item_count > 0)
444                            {
445                                    return SCAN_ARTICLE_FORWARD_BY_USER;
446                            }
447                            break;
448                    case '?':
449                            if (item_count > 0)
450                            {
451                                    return SCAN_ARTICLE_BACKWARD_BY_TITLE;
452                            }
453                            break;
454                    case '/':
455                            if (item_count > 0)
456                            {
457                                    return SCAN_ARTICLE_FORWARD_BY_TITLE;
458                            }
459                            break;
460                    case 'u':
461                            return SEARCH_USER;
462                  case 'h':                  case 'h':
463                          return SHOW_HELP;                          return SHOW_HELP;
464                  case 'x':                  case 'x':
# Line 545  int section_list_display(const char *sna Line 597  int section_list_display(const char *sna
597          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
598          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
599          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
600          ARTICLE *p_articles[BBS_article_limit_per_page];          const ARTICLE *p_articles[BBS_article_limit_per_page];
601          int article_count;          int article_count;
602          int page_count;          int page_count;
603          int ontop_start_offset;          int ontop_start_offset;
# Line 559  int section_list_display(const char *sna Line 611  int section_list_display(const char *sna
611          int page_id_cur;          int page_id_cur;
612          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
613          USER_INFO user_info;          USER_INFO user_info;
614          char user_intro[BBS_user_intro_max_len];          char user_intro[BBS_user_intro_max_len + 1];
615            char username[BBS_username_max_len + 1];
616            char username_list[1][BBS_username_max_len + 1];
617            int32_t uid;
618            int i;
619            int ok;
620            char title[BBS_article_title_max_len + 1] = "\0";
621    
622          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
623          if (p_section == NULL)          if (p_section == NULL)
624          {          {
625                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found", sname);
626                  return -1;                  return -1;
627          }          }
628    
629          if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))          if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
630          {          {
631                  log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",                  log_error("Forbid access to unauthorized section, sid=%d, uid=%d",
632                                    p_section->sid, BBS_priv.uid);                                    p_section->sid, BBS_priv.uid);
633                  return -1;                  return -1;
634          }          }
# Line 579  int section_list_display(const char *sna Line 637  int section_list_display(const char *sna
637    
638          if (get_section_info(p_section, NULL, stitle, master_list) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
639          {          {
640                  log_error("get_section_info(sid=%d) error\n", p_section->sid);                  log_error("get_section_info(sid=%d) error", p_section->sid);
641                  return -4;                  return -4;
642          }          }
643    
# Line 598  int section_list_display(const char *sna Line 656  int section_list_display(const char *sna
656                  p_article_locate = article_block_find_by_aid(aid_location);                  p_article_locate = article_block_find_by_aid(aid_location);
657                  if (p_article_locate == NULL)                  if (p_article_locate == NULL)
658                  {                  {
659                          log_error("article_block_find_by_aid(%d) error\n", aid_location);                          log_error("article_block_find_by_aid(%d) error", aid_location);
660                          return -3;                          return -3;
661                  }                  }
662    
# Line 606  int section_list_display(const char *sna Line 664  int section_list_display(const char *sna
664                                                                                  &page_id, &selected_index, &article_count);                                                                                  &page_id, &selected_index, &article_count);
665                  if (ret < 0)                  if (ret < 0)
666                  {                  {
667                          log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",                          log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error",
668                                            p_section->sid, p_article_locate->aid);                                            p_section->sid, p_article_locate->aid);
669                          return -3;                          return -3;
670                  }                  }
# Line 614  int section_list_display(const char *sna Line 672  int section_list_display(const char *sna
672    
673          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
674          {          {
675                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error");
676                  return -2;                  return -2;
677          }          }
678    
679          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
680          if (ret < 0)          if (ret < 0)
681          {          {
682                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                  log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
683                  return -3;                  return -3;
684          }          }
685    
# Line 645  int section_list_display(const char *sna Line 703  int section_list_display(const char *sna
703                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset);                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset);
704                  if (ret < 0)                  if (ret < 0)
705                  {                  {
706                          log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                          log_error("section_list_draw_items(sid=%d, page_id=%d) error", p_section->sid, page_id);
707                          return -4;                          return -4;
708                  }                  }
709    
# Line 658  int section_list_display(const char *sna Line 716  int section_list_display(const char *sna
716    
717                  if (user_online_update(sname) < 0)                  if (user_online_update(sname) < 0)
718                  {                  {
719                          log_error("user_online_update(%s) error\n", sname);                          log_error("user_online_update(%s) error", sname);
720                  }                  }
721    
722                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
723    
                 // Update current aid location  
                 section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
724                  switch (ret)                  switch (ret)
725                  {                  {
726                  case EXIT_SECTION:                  case EXIT_SECTION:
727                            // Update current aid location
728                            if (selected_index < article_count && p_articles[selected_index] != NULL)
729                            {
730                                    if (selected_index >= ontop_start_offset)
731                                    {
732                                            ret = last_article_in_section(p_section, &p_article_locate);
733                                            if (ret < 0)
734                                            {
735                                                    log_error("last_article_in_section(sid=%d) error", p_section->sid);
736                                                    return -3;
737                                            }
738                                            else if (ret == 0)
739                                            {
740                                                    section_aid_locations[section_index] = 0;
741                                            }
742                                            else // ret > 0
743                                            {
744                                                    section_aid_locations[section_index] = p_article_locate->aid;
745                                            }
746                                    }
747                                    else
748                                    {
749                                            section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
750                                    }
751                            }
752                          return 0;                          return 0;
753                  case CHANGE_PAGE:                  case CHANGE_PAGE:
754                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
755                          if (ret < 0)                          if (ret < 0)
756                          {                          {
757                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                  log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
758                                  return -3;                                  return -3;
759                          }                          }
760                          if (article_count == 0) // empty section                          if (article_count == 0) // empty section
# Line 693  int section_list_display(const char *sna Line 773  int section_list_display(const char *sna
773    
774                                  if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0)                                  if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0)
775                                  {                                  {
776                                          log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);                                          log_error("article_cache_load(aid=%d, cid=%d) error", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
777                                          break;                                          break;
778                                  }                                  }
779    
780                                  if (user_online_update("VIEW_ARTICLE") < 0)                                  if (user_online_update("VIEW_ARTICLE") < 0)
781                                  {                                  {
782                                          log_error("user_online_update(VIEW_ARTICLE) error\n");                                          log_error("user_online_update(VIEW_ARTICLE) error");
783                                  }                                  }
784    
785                                  ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,                                  ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
# Line 707  int section_list_display(const char *sna Line 787  int section_list_display(const char *sna
787    
788                                  if (article_cache_unload(&cache) < 0)                                  if (article_cache_unload(&cache) < 0)
789                                  {                                  {
790                                          log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);                                          log_error("article_cache_unload(aid=%d, cid=%d) error", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
791                                          break;                                          break;
792                                  }                                  }
793    
794                                  // Update article_view_log                                  // Update article_view_log
795                                  if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0)                                  if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0)
796                                  {                                  {
797                                          log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid);                                          log_error("article_view_log_set_viewed(aid=%d) error", p_articles[selected_index]->aid);
798                                  }                                  }
799    
800                                  switch (ret)                                  switch (ret)
# Line 730  int section_list_display(const char *sna Line 810  int section_list_display(const char *sna
810                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
811                                                          if (ret < 0)                                                          if (ret < 0)
812                                                          {                                                          {
813                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
814                                                                  return -3;                                                                  return -3;
815                                                          }                                                          }
816    
# Line 761  int section_list_display(const char *sna Line 841  int section_list_display(const char *sna
841                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
842                                                          if (ret < 0)                                                          if (ret < 0)
843                                                          {                                                          {
844                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
845                                                                  return -3;                                                                  return -3;
846                                                          }                                                          }
847    
# Line 788  int section_list_display(const char *sna Line 868  int section_list_display(const char *sna
868                                                                                                          &page_id, &selected_index, &article_count);                                                                                                          &page_id, &selected_index, &article_count);
869                                          if (ret < 0)                                          if (ret < 0)
870                                          {                                          {
871                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n",                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error",
872                                                                    p_section->sid, p_articles[selected_index]->aid, direction);                                                                    p_section->sid, p_articles[selected_index]->aid, direction);
873                                                  return -3;                                                  return -3;
874                                          }                                          }
# Line 797  int section_list_display(const char *sna Line 877  int section_list_display(const char *sna
877                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
878                                                  if (ret < 0)                                                  if (ret < 0)
879                                                  {                                                  {
880                                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                          log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
881                                                          return -3;                                                          return -3;
882                                                  }                                                  }
883                                                  loop = 1;                                                  loop = 1;
# Line 806  int section_list_display(const char *sna Line 886  int section_list_display(const char *sna
886                                  case 'r': // Reply article                                  case 'r': // Reply article
887                                          if (user_online_update("REPLY_ARTICLE") < 0)                                          if (user_online_update("REPLY_ARTICLE") < 0)
888                                          {                                          {
889                                                  log_error("user_online_update(REPLY_ARTICLE) error\n");                                                  log_error("user_online_update(REPLY_ARTICLE) error");
890                                          }                                          }
891    
892                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
893                                          {                                          {
894                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);                                                  log_error("article_reply(aid=%d) error", p_articles[selected_index]->aid);
895                                            }
896                                            else if (ret > 0) // Article replied
897                                            {
898                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
899                                                    if (ret < 0)
900                                                    {
901                                                            log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
902                                                            return -3;
903                                                    }
904                                          }                                          }
905                                          loop = 1;                                          loop = 1;
906                                          break;                                          break;
# Line 823  int section_list_display(const char *sna Line 912  int section_list_display(const char *sna
912                                                                                                          &page_id, &selected_index, &article_count);                                                                                                          &page_id, &selected_index, &article_count);
913                                          if (ret < 0)                                          if (ret < 0)
914                                          {                                          {
915                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error",
916                                                                    p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);                                                                    p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
917                                                  return -3;                                                  return -3;
918                                          }                                          }
# Line 834  int section_list_display(const char *sna Line 923  int section_list_display(const char *sna
923                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
924                                                          if (ret < 0)                                                          if (ret < 0)
925                                                          {                                                          {
926                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
927                                                                  return -3;                                                                  return -3;
928                                                          }                                                          }
929                                                  }                                                  }
# Line 849  int section_list_display(const char *sna Line 938  int section_list_display(const char *sna
938    
939                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
940                          {                          {
941                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
942                                  return -2;                                  return -2;
943                          }                          }
944                          break;                          break;
# Line 857  int section_list_display(const char *sna Line 946  int section_list_display(const char *sna
946                          display_nickname = !display_nickname;                          display_nickname = !display_nickname;
947                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
948                          {                          {
949                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
950                                  return -2;                                  return -2;
951                          }                          }
952                          break;                          break;
953                  case POST_ARTICLE:                  case POST_ARTICLE:
954                          if (user_online_update("POST_ARTICLE") < 0)                          if (user_online_update("POST_ARTICLE") < 0)
955                          {                          {
956                                  log_error("user_online_update(POST_ARTICLE) error\n");                                  log_error("user_online_update(POST_ARTICLE) error");
957                          }                          }
958    
959                          if ((ret = article_post(p_section, &article_new)) < 0)                          if ((ret = article_post(p_section, &article_new)) < 0)
960                          {                          {
961                                  log_error("article_post(sid=%d) error\n", p_section->sid);                                  log_error("article_post(sid=%d) error", p_section->sid);
962                          }                          }
963                          else if (ret > 0) // New article posted                          else if (ret > 0) // New article posted
964                          {                          {
965                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
966                                  if (ret < 0)                                  if (ret < 0)
967                                  {                                  {
968                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          log_error("query_section_articles(sid=%d, page_id=%d) error: %d", p_section->sid, page_id, ret);
969                                          return -3;                                          return -3;
970                                  }                                  }
971                          }                          }
972                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
973                          {                          {
974                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
975                                  return -2;                                  return -2;
976                          }                          }
977                          break;                          break;
# Line 895  int section_list_display(const char *sna Line 984  int section_list_display(const char *sna
984    
985                          if (user_online_update("EDIT_ARTICLE") < 0)                          if (user_online_update("EDIT_ARTICLE") < 0)
986                          {                          {
987                                  log_error("user_online_update() error\n");                                  log_error("user_online_update() error");
988                          }                          }
989    
990                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
991                          {                          {
992                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_modify(aid=%d) error", p_articles[selected_index]->aid);
993                            }
994                            else if (ret > 0) // Article modified
995                            {
996                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
997                                    if (ret < 0)
998                                    {
999                                            log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
1000                                            return -3;
1001                                    }
1002                          }                          }
1003                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1004                          {                          {
1005                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1006                                  return -2;                                  return -2;
1007                          }                          }
1008                          break;                          break;
# Line 916  int section_list_display(const char *sna Line 1014  int section_list_display(const char *sna
1014                          }                          }
1015                          if ((ret = article_del(p_section, p_articles[selected_index])) < 0)                          if ((ret = article_del(p_section, p_articles[selected_index])) < 0)
1016                          {                          {
1017                                  log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_del(aid=%d) error", p_articles[selected_index]->aid);
1018                          }                          }
1019                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
1020                          {                          {
1021                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
1022                                  {                                  {
1023                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1024                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
1025                                  }                                          {
1026                                                    selected_index = article_count - 1;
1027                                                    break;
1028                                            }
1029                                            else if (ret < 0 && page_id > 0)
1030                                            {
1031                                                    page_id--;
1032                                                    selected_index = BBS_article_limit_per_page - 1;
1033                                            }
1034                                            else if (ret < 0 && page_id <= 0)
1035                                            {
1036                                                    selected_index = 0;
1037                                                    break;
1038                                            }
1039                                    } while (ret < 0);
1040                          }                          }
1041                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1042                          {                          {
1043                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1044                                  return -2;                                  return -2;
1045                          }                          }
1046                          break;                          break;
1047                  case QUERY_ARTICLE:                  case QUERY_ARTICLE:
1048                          if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)                          if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
1049                          {                          {
1050                                  log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("display_article_meta(aid=%d) error", p_articles[selected_index]->aid);
1051                          }                          }
1052                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1053                          {                          {
1054                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1055                                  return -2;                                  return -2;
1056                          }                          }
1057                          break;                          break;
1058                  case QUERY_USER:                  case QUERY_USER:
1059                          if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)                          if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)
1060                          {                          {
1061                                  log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);                                  log_error("query_user_info_by_uid(uid=%d) error", p_articles[selected_index]->uid);
1062                                  return -2;                                  return -2;
1063                          }                          }
1064                          else if (ret == 0)                          else if (ret == 0)
# Line 958  int section_list_display(const char *sna Line 1069  int section_list_display(const char *sna
1069                          }                          }
1070                          else if (user_info_display(&user_info) < 0) // && ret > 0                          else if (user_info_display(&user_info) < 0) // && ret > 0
1071                          {                          {
1072                                  log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);                                  log_error("user_info_display(uid=%d) error", p_articles[selected_index]->uid);
1073                          }                          }
1074    
1075                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1076                          {                          {
1077                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1078                                  return -2;                                  return -2;
1079                          }                          }
1080                          break;                          break;
# Line 974  int section_list_display(const char *sna Line 1085  int section_list_display(const char *sna
1085                                                                          &BBS_article_favor, 1);                                                                          &BBS_article_favor, 1);
1086                          if (ret < 0)                          if (ret < 0)
1087                          {                          {
1088                                  log_error("article_favor_set(aid=%d, 1) error\n",                                  log_error("article_favor_set(aid=%d, 1) error",
1089                                                    p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                                                    p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
1090                          }                          }
1091                          break;                          break;
# Line 985  int section_list_display(const char *sna Line 1096  int section_list_display(const char *sna
1096                                                                          &BBS_article_favor, 0);                                                                          &BBS_article_favor, 0);
1097                          if (ret < 0)                          if (ret < 0)
1098                          {                          {
1099                                  log_error("article_favor_set(aid=%d, 0) error\n",                                  log_error("article_favor_set(aid=%d, 0) error",
1100                                                    p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                                                    p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
1101                          }                          }
1102                          break;                          break;
1103                    case SET_EXCERPTION_ARTICLE:
1104                            if (checkpriv(&BBS_priv, p_section->sid, S_POST | S_MAN_S))
1105                            {
1106                                    ret = article_excerption_set(p_section, p_articles[selected_index]->aid, (p_articles[selected_index]->excerption ? 0 : 1));
1107                                    if (ret < 0)
1108                                    {
1109                                            log_error("article_excerption_set(sid=%d, aid=%d, set=%d) error\n",
1110                                                              p_section->sid, p_articles[selected_index]->aid, (p_articles[selected_index]->excerption ? 0 : 1));
1111                                    }
1112                            }
1113                            break;
1114                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
1115                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
1116                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 997  int section_list_display(const char *sna Line 1119  int section_list_display(const char *sna
1119                                                                                          &page_id, &selected_index, &article_count);                                                                                          &page_id, &selected_index, &article_count);
1120                          if (ret < 0)                          if (ret < 0)
1121                          {                          {
1122                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error",
1123                                                    p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);                                                    p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
1124                                  return -3;                                  return -3;
1125                          }                          }
# Line 1006  int section_list_display(const char *sna Line 1128  int section_list_display(const char *sna
1128                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1129                                  if (ret < 0)                                  if (ret < 0)
1130                                  {                                  {
1131                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
1132                                            return -3;
1133                                    }
1134                            }
1135                            break;
1136                    case LAST_SECTION_ARTICLE:
1137                            page_id_cur = page_id;
1138                            ret = last_article_in_section(p_section, &p_article_locate);
1139                            if (ret < 0)
1140                            {
1141                                    log_error("last_article_in_section(sid=%d) error", p_section->sid);
1142                                    return -3;
1143                            }
1144                            else if (ret == 0)
1145                            {
1146                                    break;
1147                            }
1148                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1149                                                                                            &page_id, &selected_index, &article_count);
1150                            if (ret < 0)
1151                            {
1152                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error",
1153                                                      p_section->sid, p_article_locate->aid);
1154                                    return -3;
1155                            }
1156                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1157                            {
1158                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1159                                    if (ret < 0)
1160                                    {
1161                                            log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
1162                                          return -3;                                          return -3;
1163                                  }                                  }
1164                          }                          }
# Line 1015  int section_list_display(const char *sna Line 1167  int section_list_display(const char *sna
1167                          ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);                          ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
1168                          if (ret < 0)                          if (ret < 0)
1169                          {                          {
1170                                  log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",                                  log_error("scan_unread_article_in_section(sid=%d, aid=%d) error",
1171                                                    p_section->sid, p_articles[selected_index]->aid);                                                    p_section->sid, p_articles[selected_index]->aid);
1172                                  return -3;                                  return -3;
1173                          }                          }
# Line 1028  int section_list_display(const char *sna Line 1180  int section_list_display(const char *sna
1180                                                                                          &page_id, &selected_index, &article_count);                                                                                          &page_id, &selected_index, &article_count);
1181                          if (ret < 0)                          if (ret < 0)
1182                          {                          {
1183                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error",
1184                                                      p_section->sid, p_article_locate->aid);
1185                                    return -3;
1186                            }
1187                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1188                            {
1189                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1190                                    if (ret < 0)
1191                                    {
1192                                            log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
1193                                            return -3;
1194                                    }
1195                            }
1196                            break;
1197                    case SCAN_ARTICLE_BACKWARD_BY_USER:
1198                    case SCAN_ARTICLE_FORWARD_BY_USER:
1199                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_USER ? 1 : -1);
1200                            strncpy(username, p_articles[selected_index]->username, sizeof(username) - 1);
1201                            username[sizeof(username) - 1] = '\0';
1202                            uid = 0;
1203    
1204                            moveto(SCREEN_ROWS, 1);
1205                            clrtoeol();
1206                            get_data(SCREEN_ROWS, 1,
1207                                             (direction == 1 ? "↓搜寻作者: " : "↑搜寻作者: "),
1208                                             username, sizeof(username), BBS_username_max_len);
1209    
1210                            if (username[0] == '\0')
1211                            {
1212                                    break;
1213                            }
1214    
1215                            // Verify format
1216                            for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1217                            {
1218                                    if (!(isalpha((int)username[i]) || (i > 0 && (isdigit((int)username[i]) || username[i] == '_'))))
1219                                    {
1220                                            ok = 0;
1221                                    }
1222                            }
1223                            if (ok && i > BBS_username_max_len)
1224                            {
1225                                    ok = 0;
1226                            }
1227                            if (!ok)
1228                            {
1229                                    break;
1230                            }
1231    
1232                            ret = query_user_info_by_username(username, 1, &uid, username_list);
1233                            if (ret < 0)
1234                            {
1235                                    log_error("query_user_info_by_username(%s) error", username);
1236                                    break;
1237                            }
1238    
1239                            if (uid > 0)
1240                            {
1241                                    ret = scan_article_in_section_by_uid(p_section, p_articles[selected_index],
1242                                                                                                             direction, uid, &p_article_locate);
1243                                    if (ret < 0)
1244                                    {
1245                                            log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error",
1246                                                              p_section->sid, p_articles[selected_index]->aid, direction, uid);
1247                                            return -3;
1248                                    }
1249                                    else if (ret == 0) // not found
1250                                    {
1251                                            break;
1252                                    }
1253                            }
1254                            else // uid == 0
1255                            {
1256                                    ret = scan_article_in_section_by_username(p_section, p_articles[selected_index],
1257                                                                                                                      direction, username, &p_article_locate);
1258                                    if (ret < 0)
1259                                    {
1260                                            log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error",
1261                                                              p_section->sid, p_articles[selected_index]->aid, direction, username);
1262                                            return -3;
1263                                    }
1264                                    else if (ret == 0) // not found
1265                                    {
1266                                            break;
1267                                    }
1268                            }
1269    
1270                            page_id_cur = page_id;
1271                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1272                                                                                            &page_id, &selected_index, &article_count);
1273                            if (ret < 0)
1274                            {
1275                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error",
1276                                                      p_section->sid, p_article_locate->aid);
1277                                    return -3;
1278                            }
1279                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1280                            {
1281                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1282                                    if (ret < 0)
1283                                    {
1284                                            log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
1285                                            return -3;
1286                                    }
1287                            }
1288                            break;
1289                    case SCAN_ARTICLE_BACKWARD_BY_TITLE:
1290                    case SCAN_ARTICLE_FORWARD_BY_TITLE:
1291                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1);
1292    
1293                            moveto(SCREEN_ROWS, 1);
1294                            clrtoeol();
1295                            get_data(SCREEN_ROWS, 1,
1296                                             (direction == 1 ? "↓搜寻标题: " : "↑搜寻标题: "),
1297                                             title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1298    
1299                            if (title[0] == '\0')
1300                            {
1301                                    break;
1302                            }
1303    
1304                            ret = scan_article_in_section_by_title(p_section, p_articles[selected_index],
1305                                                                                                       direction, title, &p_article_locate);
1306                            if (ret < 0)
1307                            {
1308                                    log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error",
1309                                                      p_section->sid, p_articles[selected_index]->aid, direction, title);
1310                                    return -3;
1311                            }
1312                            else if (ret == 0) // not found
1313                            {
1314                                    break;
1315                            }
1316    
1317                            page_id_cur = page_id;
1318                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1319                                                                                            &page_id, &selected_index, &article_count);
1320                            if (ret < 0)
1321                            {
1322                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error",
1323                                                    p_section->sid, p_article_locate->aid);                                                    p_section->sid, p_article_locate->aid);
1324                                  return -3;                                  return -3;
1325                          }                          }
# Line 1037  int section_list_display(const char *sna Line 1328  int section_list_display(const char *sna
1328                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1329                                  if (ret < 0)                                  if (ret < 0)
1330                                  {                                  {
1331                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id);
1332                                          return -3;                                          return -3;
1333                                  }                                  }
1334                          }                          }
1335                          break;                          break;
1336                    case SEARCH_USER:
1337                            user_list_search();
1338                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1339                            {
1340                                    log_error("section_list_draw_screen() error");
1341                                    return -2;
1342                            }
1343                            break;
1344                  case SHOW_HELP:                  case SHOW_HELP:
1345                          // Display help information                          // Display help information
1346                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
1347                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1348                          {                          {
1349                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1350                                  return -2;                                  return -2;
1351                          }                          }
1352                          break;                          break;
1353                  case VIEW_EX_DIR:                  case VIEW_EX_DIR:
1354                          if (section_list_ex_dir_display(p_section) < 0)                          if (section_list_ex_dir_display(p_section) < 0)
1355                          {                          {
1356                                  log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);                                  log_error("section_list_ex_dir_display(sid=%d) error", p_section->sid);
1357                          }                          }
1358                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1359                          {                          {
1360                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1361                                  return -2;                                  return -2;
1362                          }                          }
1363                          break;                          break;
# Line 1066  int section_list_display(const char *sna Line 1365  int section_list_display(const char *sna
1365                          show_top10_menu(NULL);                          show_top10_menu(NULL);
1366                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1367                          {                          {
1368                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error");
1369                                  return -2;                                  return -2;
1370                          }                          }
1371                          break;                          break;
1372                  default:                  default:
1373                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d", ret);
1374                  }                  }
1375          }          }
1376    
# Line 1082  int section_list_ex_dir_display(SECTION_ Line 1381  int section_list_ex_dir_display(SECTION_
1381  {  {
1382          MENU_SET ex_menu_set;          MENU_SET ex_menu_set;
1383          int ch = 0;          int ch = 0;
1384            int loop;
1385    
1386          if (p_section == NULL)          if (p_section == NULL)
1387          {          {
1388                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
1389                  return -1;                  return -1;
1390          }          }
1391    
# Line 1100  int section_list_ex_dir_display(SECTION_ Line 1400  int section_list_ex_dir_display(SECTION_
1400    
1401          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
1402          {          {
1403                  log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);                  log_error("get_section_ex_menu_set(sid=%d) error", p_section->sid);
1404                  return -3;                  return -3;
1405          }          }
1406          if (get_menu_shm_readonly(&ex_menu_set) < 0)          if (get_menu_shm_readonly(&ex_menu_set) < 0)
1407          {          {
1408                  log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid);                  log_error("get_menu_shm_readonly(sid=%d) error", p_section->sid);
1409                  return -3;                  return -3;
1410          }          }
1411    
# Line 1114  int section_list_ex_dir_display(SECTION_ Line 1414  int section_list_ex_dir_display(SECTION_
1414    
1415          if (display_menu(&ex_menu_set) == 0)          if (display_menu(&ex_menu_set) == 0)
1416          {          {
1417                  while (!SYS_server_exit)                  for (loop = 1; !SYS_server_exit && loop;)
1418                  {                  {
1419                          iflush();                          iflush();
1420                          ch = igetch(100);                          ch = igetch(100);
# Line 1122  int section_list_ex_dir_display(SECTION_ Line 1422  int section_list_ex_dir_display(SECTION_
1422                          if (ch != KEY_NULL && ch != KEY_TIMEOUT)                          if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1423                          {                          {
1424                                  BBS_last_access_tm = time(NULL);                                  BBS_last_access_tm = time(NULL);
1425    
1426                                    // Refresh current action
1427                                    if (user_online_update(NULL) < 0)
1428                                    {
1429                                            log_error("user_online_update(NULL) error");
1430                                    }
1431                          }                          }
1432    
1433                          switch (ch)                          switch (ch)
1434                          {                          {
1435                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1436                                  log_error("KEY_NULL\n");                                  log_debug("KEY_NULL");
1437                                  return 0;                                  loop = 0;
1438                                    break;
1439                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1440                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
1441                                  {                                  {
1442                                          log_error("User input timeout\n");                                          log_debug("User input timeout");
1443                                          return 0;                                          loop = 0;
1444                                            break;
1445                                  }                                  }
1446                                  continue;                                  continue;
1447                          case CR:                          case CR:
# Line 1141  int section_list_ex_dir_display(SECTION_ Line 1449  int section_list_ex_dir_display(SECTION_
1449                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1450                                  {                                  {
1451                                  case EXITMENU:                                  case EXITMENU:
1452                                          ch = EXITMENU;                                          loop = 0;
1453                                          break;                                          break;
1454                                  case REDRAW:                                  case REDRAW:
1455                                          clearscr();                                          clearscr();
# Line 1154  int section_list_ex_dir_display(SECTION_ Line 1462  int section_list_ex_dir_display(SECTION_
1462                                          break;                                          break;
1463                                  }                                  }
1464                          }                          }
   
                         if (ch == EXITMENU)  
                         {  
                                 break;  
                         }  
1465                  }                  }
1466          }          }
1467    
# Line 1178  int section_aid_locations_save(int uid) Line 1481  int section_aid_locations_save(int uid)
1481    
1482          if ((fp = fopen(filename, "wb")) == NULL)          if ((fp = fopen(filename, "wb")) == NULL)
1483          {          {
1484                  log_error("fopen(%s, wb) error: %d\n", filename, errno);                  log_error("fopen(%s, wb) error: %d", filename, errno);
1485                  return -1;                  return -1;
1486          }          }
1487    
# Line 1186  int section_aid_locations_save(int uid) Line 1489  int section_aid_locations_save(int uid)
1489          {          {
1490                  if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)                  if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1491                  {                  {
1492                          log_error("fwrite(%s, sid) error\n", filename);                          log_error("fwrite(%s, sid) error", filename);
1493                          ret = -2;                          ret = -2;
1494                          break;                          break;
1495                  }                  }
1496    
1497                  if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)                  if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1498                  {                  {
1499                          log_error("fwrite(%s, aid) error\n", filename);                          log_error("fwrite(%s, aid) error", filename);
1500                          ret = -2;                          ret = -2;
1501                          break;                          break;
1502                  }                  }
# Line 1201  int section_aid_locations_save(int uid) Line 1504  int section_aid_locations_save(int uid)
1504    
1505          if (fclose(fp) < 0)          if (fclose(fp) < 0)
1506          {          {
1507                  log_error("fclose(%s) error: %d\n", filename, errno);                  log_error("fclose(%s) error: %d", filename, errno);
1508                  ret = -1;                  ret = -1;
1509          }          }
1510    
# Line 1226  int section_aid_locations_load(int uid) Line 1529  int section_aid_locations_load(int uid)
1529                  {                  {
1530                          return 0;                          return 0;
1531                  }                  }
1532                  log_error("fopen(%s, rb) error: %d\n", filename, errno);                  log_error("fopen(%s, rb) error: %d", filename, errno);
1533                  return -1;                  return -1;
1534          }          }
1535    
# Line 1238  int section_aid_locations_load(int uid) Line 1541  int section_aid_locations_load(int uid)
1541                          {                          {
1542                                  break;                                  break;
1543                          }                          }
1544                          log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));                          log_error("fread(%s, sid) error: %d", filename, ferror(fp));
1545                          ret = -2;                          ret = -2;
1546                          break;                          break;
1547                  }                  }
# Line 1249  int section_aid_locations_load(int uid) Line 1552  int section_aid_locations_load(int uid)
1552                          {                          {
1553                                  break;                                  break;
1554                          }                          }
1555                          log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));                          log_error("fread(%s, aid) error: %d", filename, ferror(fp));
1556                          ret = -2;                          ret = -2;
1557                          break;                          break;
1558                  }                  }
# Line 1263  int section_aid_locations_load(int uid) Line 1566  int section_aid_locations_load(int uid)
1566                  i = get_section_index(p_section);                  i = get_section_index(p_section);
1567                  if (i < 0)                  if (i < 0)
1568                  {                  {
1569                          log_error("get_section_index(sid=%d) error\n", sid);                          log_error("get_section_index(sid=%d) error", sid);
1570                          ret = -3;                          ret = -3;
1571                          break;                          break;
1572                  }                  }
# Line 1272  int section_aid_locations_load(int uid) Line 1575  int section_aid_locations_load(int uid)
1575    
1576          if (fclose(fp) < 0)          if (fclose(fp) < 0)
1577          {          {
1578                  log_error("fclose(%s) error: %d\n", filename, errno);                  log_error("fclose(%s) error: %d", filename, errno);
1579                  ret = -1;                  ret = -1;
1580          }          }
1581    


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

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