/[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.48 by sysadm, Mon Oct 13 07:35:48 2025 UTC Revision 1.67 by sysadm, Mon Nov 3 15:06:46 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_favor.h"
19  #include "article_op.h"  #include "article_op.h"
20  #include "article_post.h"  #include "article_post.h"
21  #include "article_view_log.h"  #include "article_view_log.h"
# Line 29  Line 30 
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
32  #include "str_process.h"  #include "str_process.h"
33    #include "user_info_display.h"
34    #include "user_list_display.h"
35  #include "user_priv.h"  #include "user_priv.h"
36    #include <ctype.h>
37    #include <errno.h>
38  #include <string.h>  #include <string.h>
39  #include <time.h>  #include <time.h>
40  #include <sys/param.h>  #include <sys/param.h>
41    
42  static int section_aid_locations[BBS_max_section] = {0};  #define TITLE_SEARCH_MAX_LEN 60
43    
44    static int32_t section_aid_locations[BBS_max_section] = {0};
45  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
46  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
47    
# Line 49  enum select_cmd_t Line 56  enum select_cmd_t
56          EDIT_ARTICLE,          EDIT_ARTICLE,
57          DELETE_ARTICLE,          DELETE_ARTICLE,
58          QUERY_ARTICLE,          QUERY_ARTICLE,
59            QUERY_USER,
60            SET_FAVOR_ARTICLE,
61            UNSET_FAVOR_ARTICLE,
62          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
63          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
64          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
65            SCAN_ARTICLE_BACKWARD_BY_USER,
66            SCAN_ARTICLE_FORWARD_BY_USER,
67            SCAN_ARTICLE_BACKWARD_BY_TITLE,
68            SCAN_ARTICLE_FORWARD_BY_TITLE,
69          VIEW_EX_DIR,          VIEW_EX_DIR,
70          SHOW_TOP10,          SHOW_TOP10,
71            SEARCH_USER,
72  };  };
73    
74  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, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 68  static int section_list_draw_items(int p Line 83  static int section_list_draw_items(int p
83          size_t j;          size_t j;
84          char article_flag;          char article_flag;
85          int is_viewed;          int is_viewed;
86            int is_favor;
87          time_t tm_now;          time_t tm_now;
88    
89          time(&tm_now);          time(&tm_now);
# Line 90  static int section_list_draw_items(int p Line 106  static int section_list_draw_items(int p
106                          }                          }
107                  }                  }
108    
109                    if (p_articles[i]->tid == 0)
110                    {
111                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
112                            if (is_favor < 0)
113                            {
114                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
115                                    is_favor = 0;
116                            }
117                    }
118                    else
119                    {
120                            is_favor = 0;
121                    }
122    
123                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
124                  {                  {
125                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 136  static int section_list_draw_items(int p Line 166  static int section_list_draw_items(int p
166                  }                  }
167                  strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
168    
169                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  len = split_line(title_f, 59 - (display_nickname ? BBS_nickname_max_len / 2 : BBS_username_max_len), &eol, &title_f_len, 1);
170                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
171                  {                  {
172                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 145  static int section_list_draw_items(int p Line 175  static int section_list_draw_items(int p
175                  moveto(4 + i, 1);                  moveto(4 + i, 1);
176                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
177                  {                  {
178                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m%c%c %s%*s %s %s%s\033[m",
179                                       (is_favor ? '@' : ' '),
180                                     article_flag,                                     article_flag,
181                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
182                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
# Line 161  static int section_list_draw_items(int p Line 192  static int section_list_draw_items(int p
192                  }                  }
193                  else                  else
194                  {                  {
195                          prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                          prints("  %s%7d\033[m%c%c %s%*s %s %s%s\033[m",
196                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
197                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
198                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
199                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
200                                                             : "")),                                                             : "")),
201                                     p_articles[i]->aid,                                     p_articles[i]->aid,
202                                       (is_favor ? '@' : ' '),
203                                     article_flag,                                     article_flag,
204                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
205                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
# Line 235  static enum select_cmd_t section_list_se Line 267  static enum select_cmd_t section_list_se
267          {          {
268                  ch = igetch(100);                  ch = igetch(100);
269    
270                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
271                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
272                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
273                  case KEY_NULL:                   // broken pipe                  }
274                          return EXIT_SECTION; // exit section  
275                    switch (ch)
276                    {
277                    case KEY_NULL: // broken pipe
278                            log_error("KEY_NULL\n");
279                            return EXIT_SECTION;
280                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
281                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
282                          {                          {
283                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
284                                    return EXIT_SECTION;
285                          }                          }
286                          continue;                          continue;
287                    case KEY_ESC:
288                    case KEY_LEFT:
289                            return EXIT_SECTION;
290                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
291                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
292                  case CR:                  case CR:
                         igetch_reset();  
293                  case 'r':                  case 'r':
294                  case KEY_RIGHT:                  case KEY_RIGHT:
295                          if (item_count > 0)                          if (item_count > 0)
296                          {                          {
                                 BBS_last_access_tm = time(NULL);  
297                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
298                          }                          }
299                          break;                          break;
# Line 281  static enum select_cmd_t section_list_se Line 317  static enum select_cmd_t section_list_se
317                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
318                          }                          }
319                          break;                          break;
320                    case Ctrl('A'):
321                            if (item_count > 0)
322                            {
323                                    return QUERY_USER;
324                            }
325                            break;
326                    case 'F':
327                            if (item_count > 0)
328                            {
329                                    return SET_FAVOR_ARTICLE;
330                            }
331                            break;
332                    case '-':
333                            if (item_count > 0)
334                            {
335                                    return UNSET_FAVOR_ARTICLE;
336                            }
337                            break;
338                  case KEY_HOME:                  case KEY_HOME:
339                          *p_page_id = 0;                          *p_page_id = 0;
340                  case 'P':                  case 'P':
# Line 362  static enum select_cmd_t section_list_se Line 416  static enum select_cmd_t section_list_se
416                                  return SCAN_NEW_ARTICLE;                                  return SCAN_NEW_ARTICLE;
417                          }                          }
418                          break;                          break;
419                    case 'A':
420                            if (item_count > 0)
421                            {
422                                    return SCAN_ARTICLE_BACKWARD_BY_USER;
423                            }
424                            break;
425                    case 'a':
426                            if (item_count > 0)
427                            {
428                                    return SCAN_ARTICLE_FORWARD_BY_USER;
429                            }
430                            break;
431                    case '?':
432                            if (item_count > 0)
433                            {
434                                    return SCAN_ARTICLE_BACKWARD_BY_TITLE;
435                            }
436                            break;
437                    case '/':
438                            if (item_count > 0)
439                            {
440                                    return SCAN_ARTICLE_FORWARD_BY_TITLE;
441                            }
442                            break;
443                    case 'u':
444                            return SEARCH_USER;
445                  case 'h':                  case 'h':
446                          return SHOW_HELP;                          return SHOW_HELP;
447                  case 'x':                  case 'x':
448                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
449                  case Ctrl('H'):                  case 'H':
450                          return SHOW_TOP10;                          return SHOW_TOP10;
451                  default:                  default:
452                            break;
453                  }                  }
454    
455                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 393  static enum select_cmd_t section_list_se Line 474  static enum select_cmd_t section_list_se
474                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
475                  }                  }
476    
                 BBS_last_access_tm = time(NULL);  
477                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
478                  {                  {
479                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 513  int section_list_display(const char *sna Line 593  int section_list_display(const char *sna
593          ARTICLE article_new;          ARTICLE article_new;
594          int page_id_cur;          int page_id_cur;
595          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
596            USER_INFO user_info;
597            char user_intro[BBS_user_intro_max_len + 1];
598            char username[BBS_username_max_len + 1];
599            char username_list[1][BBS_username_max_len + 1];
600            int32_t uid;
601            int i;
602            int ok;
603            char title[BBS_article_title_max_len + 1] = "\0";
604    
605          p_section = section_list_find_by_name(sname, &section_index);          p_section = section_list_find_by_name(sname);
606          if (p_section == NULL)          if (p_section == NULL)
607          {          {
608                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
609                  return -1;                  return -1;
610          }          }
611    
612          if ((ret = section_list_rd_lock(p_section)) < 0)          if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
613          {          {
614                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
615                  return -2;                                    p_section->sid, BBS_priv.uid);
616                    return -1;
617          }          }
618    
619          strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);          section_index = get_section_index(p_section);
         stitle[sizeof(stitle) - 1] = '\0';  
         strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);  
         master_list[sizeof(master_list) - 1] = '\0';  
620    
621          if ((ret = section_list_rd_unlock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
622          {          {
623                  log_error("section_list_rd_unlock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
624                  return -2;                  return -4;
625          }          }
626    
627          if (aid == 0)          if (aid == 0)
# Line 545  int section_list_display(const char *sna Line 631  int section_list_display(const char *sna
631          else          else
632          {          {
633                  aid_location = aid;                  aid_location = aid;
634          }                }
635    
636          // Locate at article with aid_locate          // Locate at article with aid_locate
637          if (aid_location > 0)          if (aid_location > 0)
# Line 617  int section_list_display(const char *sna Line 703  int section_list_display(const char *sna
703                  }                  }
704    
705                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
706    
707                  switch (ret)                  switch (ret)
708                  {                  {
709                  case EXIT_SECTION:                  case EXIT_SECTION:
710                            // Update current aid location
711                            if (p_articles[selected_index] != NULL)
712                            {
713                                    section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
714                            }
715                          return 0;                          return 0;
716                  case CHANGE_PAGE:                  case CHANGE_PAGE:
717                          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);
# Line 764  int section_list_display(const char *sna Line 856  int section_list_display(const char *sna
856                                          {                                          {
857                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
858                                          }                                          }
859                                            else if (ret > 0) // Article replied
860                                            {
861                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
862                                                    if (ret < 0)
863                                                    {
864                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
865                                                            return -3;
866                                                    }
867                                            }
868                                          loop = 1;                                          loop = 1;
869                                          break;                                          break;
870                                  case '=':  // First topic article                                  case '=':  // First topic article
# Line 798  int section_list_display(const char *sna Line 899  int section_list_display(const char *sna
899                          // Update current topic                          // Update current topic
900                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
901    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
902                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
903                          {                          {
904                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 830  int section_list_display(const char *sna Line 928  int section_list_display(const char *sna
928                                  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);
929                                  if (ret < 0)                                  if (ret < 0)
930                                  {                                  {
931                                          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\n", p_section->sid, page_id, ret);
932                                          return -3;                                          return -3;
933                                  }                                  }
934                          }                          }
# Line 856  int section_list_display(const char *sna Line 954  int section_list_display(const char *sna
954                          {                          {
955                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
956                          }                          }
957                            else if (ret > 0) // Article modified
958                            {
959                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
960                                    if (ret < 0)
961                                    {
962                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
963                                            return -3;
964                                    }
965                            }
966                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
967                          {                          {
968                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 874  int section_list_display(const char *sna Line 981  int section_list_display(const char *sna
981                          }                          }
982                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
983                          {                          {
984                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
985                                  {                                  {
986                                          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);
987                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
988                                  }                                          {
989                                                    selected_index = article_count - 1;
990                                                    break;
991                                            }
992                                            else if (ret < 0 && page_id > 0)
993                                            {
994                                                    page_id--;
995                                                    selected_index = BBS_article_limit_per_page - 1;
996                                            }
997                                            else if (ret < 0 && page_id <= 0)
998                                            {
999                                                    selected_index = 0;
1000                                                    break;
1001                                            }
1002                                    } while (ret < 0);
1003                          }                          }
1004                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1005                          {                          {
# Line 898  int section_list_display(const char *sna Line 1018  int section_list_display(const char *sna
1018                                  return -2;                                  return -2;
1019                          }                          }
1020                          break;                          break;
1021                    case QUERY_USER:
1022                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)
1023                            {
1024                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
1025                                    return -2;
1026                            }
1027                            else if (ret == 0)
1028                            {
1029                                    clearscr();
1030                                    prints("该用户已升天");
1031                                    press_any_key();
1032                            }
1033                            else if (user_info_display(&user_info) < 0) // && ret > 0
1034                            {
1035                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
1036                            }
1037    
1038                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1039                            {
1040                                    log_error("section_list_draw_screen() error\n");
1041                                    return -2;
1042                            }
1043                            break;
1044                    case SET_FAVOR_ARTICLE:
1045                            ret = article_favor_set(p_articles[selected_index]->tid == 0
1046                                                                                    ? p_articles[selected_index]->aid
1047                                                                                    : p_articles[selected_index]->tid,
1048                                                                            &BBS_article_favor, 1);
1049                            if (ret < 0)
1050                            {
1051                                    log_error("article_favor_set(aid=%d, 1) error\n",
1052                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
1053                            }
1054                            break;
1055                    case UNSET_FAVOR_ARTICLE:
1056                            ret = article_favor_set(p_articles[selected_index]->tid == 0
1057                                                                                    ? p_articles[selected_index]->aid
1058                                                                                    : p_articles[selected_index]->tid,
1059                                                                            &BBS_article_favor, 0);
1060                            if (ret < 0)
1061                            {
1062                                    log_error("article_favor_set(aid=%d, 0) error\n",
1063                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
1064                            }
1065                            break;
1066                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
1067                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
1068                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 951  int section_list_display(const char *sna Line 1116  int section_list_display(const char *sna
1116                                  }                                  }
1117                          }                          }
1118                          break;                          break;
1119                    case SCAN_ARTICLE_BACKWARD_BY_USER:
1120                    case SCAN_ARTICLE_FORWARD_BY_USER:
1121                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_USER ? 1 : -1);
1122                            strncpy(username, p_articles[selected_index]->username, sizeof(username) - 1);
1123                            username[sizeof(username) - 1] = '\0';
1124                            uid = 0;
1125    
1126                            moveto(SCREEN_ROWS, 1);
1127                            clrtoeol();
1128                            get_data(SCREEN_ROWS, 1,
1129                                             (direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "),
1130                                             username, sizeof(username), BBS_username_max_len);
1131    
1132                            if (username[0] == '\0')
1133                            {
1134                                    break;
1135                            }
1136    
1137                            // Verify format
1138                            for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1139                            {
1140                                    if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))
1141                                    {
1142                                            ok = 0;
1143                                    }
1144                            }
1145                            if (ok && i > BBS_username_max_len)
1146                            {
1147                                    ok = 0;
1148                            }
1149                            if (!ok)
1150                            {
1151                                    break;
1152                            }
1153    
1154                            ret = query_user_info_by_username(username, 1, &uid, username_list);
1155                            if (ret < 0)
1156                            {
1157                                    log_error("query_user_info_by_username(%s) error\n", username);
1158                                    break;
1159                            }
1160    
1161                            if (uid > 0)
1162                            {
1163                                    ret = scan_article_in_section_by_uid(p_section, p_articles[selected_index],
1164                                                                                                             direction, uid, &p_article_locate);
1165                                    if (ret < 0)
1166                                    {
1167                                            log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n",
1168                                                              p_section->sid, p_articles[selected_index]->aid, direction, uid);
1169                                            return -3;
1170                                    }
1171                                    else if (ret == 0) // not found
1172                                    {
1173                                            break;
1174                                    }
1175                            }
1176                            else // uid == 0
1177                            {
1178                                    ret = scan_article_in_section_by_username(p_section, p_articles[selected_index],
1179                                                                                                                      direction, username, &p_article_locate);
1180                                    if (ret < 0)
1181                                    {
1182                                            log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n",
1183                                                              p_section->sid, p_articles[selected_index]->aid, direction, username);
1184                                            return -3;
1185                                    }
1186                                    else if (ret == 0) // not found
1187                                    {
1188                                            break;
1189                                    }
1190                            }
1191    
1192                            page_id_cur = page_id;
1193                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1194                                                                                            &page_id, &selected_index, &article_count);
1195                            if (ret < 0)
1196                            {
1197                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1198                                                      p_section->sid, p_article_locate->aid);
1199                                    return -3;
1200                            }
1201                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1202                            {
1203                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1204                                    if (ret < 0)
1205                                    {
1206                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1207                                            return -3;
1208                                    }
1209                            }
1210                            break;
1211                    case SCAN_ARTICLE_BACKWARD_BY_TITLE:
1212                    case SCAN_ARTICLE_FORWARD_BY_TITLE:
1213                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1);
1214    
1215                            moveto(SCREEN_ROWS, 1);
1216                            clrtoeol();
1217                            get_data(SCREEN_ROWS, 1,
1218                                             (direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "),
1219                                             title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1220    
1221                            if (title[0] == '\0')
1222                            {
1223                                    break;
1224                            }
1225    
1226                            ret = scan_article_in_section_by_title(p_section, p_articles[selected_index],
1227                                                                                                       direction, title, &p_article_locate);
1228                            if (ret < 0)
1229                            {
1230                                    log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n",
1231                                                      p_section->sid, p_articles[selected_index]->aid, direction, title);
1232                                    return -3;
1233                            }
1234                            else if (ret == 0) // not found
1235                            {
1236                                    break;
1237                            }
1238    
1239                            page_id_cur = page_id;
1240                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1241                                                                                            &page_id, &selected_index, &article_count);
1242                            if (ret < 0)
1243                            {
1244                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1245                                                      p_section->sid, p_article_locate->aid);
1246                                    return -3;
1247                            }
1248                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1249                            {
1250                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1251                                    if (ret < 0)
1252                                    {
1253                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1254                                            return -3;
1255                                    }
1256                            }
1257                            break;
1258                    case SEARCH_USER:
1259                            user_list_search();
1260                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1261                            {
1262                                    log_error("section_list_draw_screen() error\n");
1263                                    return -2;
1264                            }
1265                            break;
1266                  case SHOW_HELP:                  case SHOW_HELP:
1267                          // Display help information                          // Display help information
1268                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 1027  int section_list_ex_dir_display(SECTION_ Line 1339  int section_list_ex_dir_display(SECTION_
1339                  {                  {
1340                          iflush();                          iflush();
1341                          ch = igetch(100);                          ch = igetch(100);
1342    
1343                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1344                            {
1345                                    BBS_last_access_tm = time(NULL);
1346                            }
1347    
1348                          switch (ch)                          switch (ch)
1349                          {                          {
1350                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1351                                    log_error("KEY_NULL\n");
1352                                  return 0;                                  return 0;
1353                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1354                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1355                                  {                                  {
1356                                            log_error("User input timeout\n");
1357                                          return 0;                                          return 0;
1358                                  }                                  }
1359                                  continue;                                  continue;
1360                          case CR:                          case CR:
                                 igetch_reset();  
1361                          default:                          default:
1362                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1363                                  {                                  {
# Line 1057  int section_list_ex_dir_display(SECTION_ Line 1376  int section_list_ex_dir_display(SECTION_
1376                                  }                                  }
1377                          }                          }
1378    
                         BBS_last_access_tm = time(NULL);  
   
1379                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1380                          {                          {
1381                                  break;                                  break;
# Line 1070  int section_list_ex_dir_display(SECTION_ Line 1387  int section_list_ex_dir_display(SECTION_
1387    
1388          return 0;          return 0;
1389  }  }
1390    
1391    int section_aid_locations_save(int uid)
1392    {
1393            char filename[FILE_PATH_LEN];
1394            FILE *fp;
1395            int i;
1396            int ret = 0;
1397    
1398            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1399    
1400            if ((fp = fopen(filename, "wb")) == NULL)
1401            {
1402                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1403                    return -1;
1404            }
1405    
1406            for (i = 0; i < p_section_list_pool->section_count; i++)
1407            {
1408                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1409                    {
1410                            log_error("fwrite(%s, sid) error\n", filename);
1411                            ret = -2;
1412                            break;
1413                    }
1414    
1415                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1416                    {
1417                            log_error("fwrite(%s, aid) error\n", filename);
1418                            ret = -2;
1419                            break;
1420                    }
1421            }
1422    
1423            if (fclose(fp) < 0)
1424            {
1425                    log_error("fclose(%s) error: %d\n", filename, errno);
1426                    ret = -1;
1427            }
1428    
1429            return ret;
1430    }
1431    
1432    int section_aid_locations_load(int uid)
1433    {
1434            char filename[FILE_PATH_LEN];
1435            FILE *fp;
1436            int i;
1437            int32_t sid;
1438            int32_t aid;
1439            SECTION_LIST *p_section;
1440            int ret = 0;
1441    
1442            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1443    
1444            if ((fp = fopen(filename, "rb")) == NULL)
1445            {
1446                    if (errno == ENOENT) // file not exist
1447                    {
1448                            return 0;
1449                    }
1450                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1451                    return -1;
1452            }
1453    
1454            while (!feof(fp))
1455            {
1456                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1457                    {
1458                            if (ferror(fp) == 0)
1459                            {
1460                                    break;
1461                            }
1462                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1463                            ret = -2;
1464                            break;
1465                    }
1466    
1467                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1468                    {
1469                            if (ferror(fp) == 0)
1470                            {
1471                                    break;
1472                            }
1473                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1474                            ret = -2;
1475                            break;
1476                    }
1477    
1478                    p_section = section_list_find_by_sid(sid);
1479                    if (p_section == NULL)
1480                    {
1481                            continue; // skip section no longer exist
1482                    }
1483    
1484                    i = get_section_index(p_section);
1485                    if (i < 0)
1486                    {
1487                            log_error("get_section_index(sid=%d) error\n", sid);
1488                            ret = -3;
1489                            break;
1490                    }
1491                    section_aid_locations[i] = aid;
1492            }
1493    
1494            if (fclose(fp) < 0)
1495            {
1496                    log_error("fclose(%s) error: %d\n", filename, errno);
1497                    ret = -1;
1498            }
1499    
1500            return ret;
1501    }


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

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