/[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.43 by sysadm, Tue Sep 30 15:06:42 2025 UTC Revision 1.64 by sysadm, Mon Nov 3 06:43:55 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 24  Line 25 
25  #include "log.h"  #include "log.h"
26  #include "login.h"  #include "login.h"
27  #include "menu.h"  #include "menu.h"
28    #include "menu_proc.h"
29  #include "section_list_display.h"  #include "section_list_display.h"
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 <errno.h>
37  #include <string.h>  #include <string.h>
38  #include <time.h>  #include <time.h>
39  #include <sys/param.h>  #include <sys/param.h>
40    
41    static int32_t section_aid_locations[BBS_max_section] = {0};
42  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
43  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
44    
# Line 47  enum select_cmd_t Line 53  enum select_cmd_t
53          EDIT_ARTICLE,          EDIT_ARTICLE,
54          DELETE_ARTICLE,          DELETE_ARTICLE,
55          QUERY_ARTICLE,          QUERY_ARTICLE,
56            QUERY_USER,
57            SET_FAVOR_ARTICLE,
58            UNSET_FAVOR_ARTICLE,
59          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
60          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
61            SCAN_NEW_ARTICLE,
62            SCAN_ARTICLE_BACKWARD_BY_USER,
63            SCAN_ARTICLE_FORWARD_BY_USER,
64          VIEW_EX_DIR,          VIEW_EX_DIR,
65            SHOW_TOP10,
66            SEARCH_USER,
67  };  };
68    
69  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 64  static int section_list_draw_items(int p Line 78  static int section_list_draw_items(int p
78          size_t j;          size_t j;
79          char article_flag;          char article_flag;
80          int is_viewed;          int is_viewed;
81            int is_favor;
82          time_t tm_now;          time_t tm_now;
83    
84          time(&tm_now);          time(&tm_now);
# Line 86  static int section_list_draw_items(int p Line 101  static int section_list_draw_items(int p
101                          }                          }
102                  }                  }
103    
104                    if (p_articles[i]->tid == 0)
105                    {
106                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
107                            if (is_favor < 0)
108                            {
109                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
110                                    is_favor = 0;
111                            }
112                    }
113                    else
114                    {
115                            is_favor = 0;
116                    }
117    
118                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
119                  {                  {
120                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 132  static int section_list_draw_items(int p Line 161  static int section_list_draw_items(int p
161                  }                  }
162                  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)));
163    
164                  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);
165                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
166                  {                  {
167                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 141  static int section_list_draw_items(int p Line 170  static int section_list_draw_items(int p
170                  moveto(4 + i, 1);                  moveto(4 + i, 1);
171                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
172                  {                  {
173                          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",
174                                       (is_favor ? '@' : ' '),
175                                     article_flag,                                     article_flag,
176                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
177                                     (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 157  static int section_list_draw_items(int p Line 187  static int section_list_draw_items(int p
187                  }                  }
188                  else                  else
189                  {                  {
190                          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",
191                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
192                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
193                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
194                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
195                                                             : "")),                                                             : "")),
196                                     p_articles[i]->aid,                                     p_articles[i]->aid,
197                                       (is_favor ? '@' : ' '),
198                                     article_flag,                                     article_flag,
199                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
200                                     (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 231  static enum select_cmd_t section_list_se Line 262  static enum select_cmd_t section_list_se
262          {          {
263                  ch = igetch(100);                  ch = igetch(100);
264    
265                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
266                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
267                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
268                  case KEY_NULL:                   // broken pipe                  }
269                          return EXIT_SECTION; // exit section  
270                    switch (ch)
271                    {
272                    case KEY_NULL: // broken pipe
273                            log_error("KEY_NULL\n");
274                            return EXIT_SECTION;
275                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
276                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
277                          {                          {
278                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
279                                    return EXIT_SECTION;
280                          }                          }
281                          continue;                          continue;
282                    case KEY_ESC:
283                    case KEY_LEFT:
284                            return EXIT_SECTION;
285                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
286                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
287                  case CR:                  case CR:
                         igetch_reset();  
288                  case 'r':                  case 'r':
289                  case KEY_RIGHT:                  case KEY_RIGHT:
290                          if (item_count > 0)                          if (item_count > 0)
291                          {                          {
                                 BBS_last_access_tm = time(NULL);  
292                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
293                          }                          }
294                          break;                          break;
# Line 277  static enum select_cmd_t section_list_se Line 312  static enum select_cmd_t section_list_se
312                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
313                          }                          }
314                          break;                          break;
315                    case Ctrl('A'):
316                            if (item_count > 0)
317                            {
318                                    return QUERY_USER;
319                            }
320                            break;
321                    case 'F':
322                            if (item_count > 0)
323                            {
324                                    return SET_FAVOR_ARTICLE;
325                            }
326                            break;
327                    case '-':
328                            if (item_count > 0)
329                            {
330                                    return UNSET_FAVOR_ARTICLE;
331                            }
332                            break;
333                  case KEY_HOME:                  case KEY_HOME:
334                          *p_page_id = 0;                          *p_page_id = 0;
335                  case 'P':                  case 'P':
# Line 291  static enum select_cmd_t section_list_se Line 344  static enum select_cmd_t section_list_se
344                                          (*p_page_id)--;                                          (*p_page_id)--;
345                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
346                                  }                                  }
347                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
348                                    {
349                                            if (total_page > 0)
350                                            {
351                                                    *p_page_id = total_page - 1;
352                                            }
353                                            if (item_count > 0)
354                                            {
355                                                    *p_selected_index = item_count - 1;
356                                            }
357                                    }
358                          }                          }
359                          else                          else
360                          {                          {
# Line 318  static enum select_cmd_t section_list_se Line 382  static enum select_cmd_t section_list_se
382                                          (*p_page_id)++;                                          (*p_page_id)++;
383                                          *p_selected_index = 0;                                          *p_selected_index = 0;
384                                  }                                  }
385                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
386                                  {                                  {
387                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
388                                            *p_selected_index = 0;
389                                  }                                  }
390                          }                          }
391                          else                          else
# Line 340  static enum select_cmd_t section_list_se Line 405  static enum select_cmd_t section_list_se
405                                  return LAST_TOPIC_ARTICLE;                                  return LAST_TOPIC_ARTICLE;
406                          }                          }
407                          break;                          break;
408                    case 'S':
409                            if (item_count > 0)
410                            {
411                                    return SCAN_NEW_ARTICLE;
412                            }
413                            break;
414                    case 'A':
415                            if (item_count > 0)
416                            {
417                                    return SCAN_ARTICLE_BACKWARD_BY_USER;
418                            }
419                            break;
420                    case 'a':
421                            if (item_count > 0)
422                            {
423                                    return SCAN_ARTICLE_FORWARD_BY_USER;
424                            }
425                            break;
426                    case 'u':
427                            return SEARCH_USER;
428                  case 'h':                  case 'h':
429                          return SHOW_HELP;                          return SHOW_HELP;
430                  case 'x':                  case 'x':
431                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
432                    case 'H':
433                            return SHOW_TOP10;
434                  default:                  default:
435                            break;
436                  }                  }
437    
438                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 369  static enum select_cmd_t section_list_se Line 457  static enum select_cmd_t section_list_se
457                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
458                  }                  }
459    
                 BBS_last_access_tm = time(NULL);  
460                  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)
461                  {                  {
462                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 466  static int display_article_key_handler(i Line 553  static int display_article_key_handler(i
553          return 0;          return 0;
554  }  }
555    
556  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
557  {  {
558          static int display_nickname = 0;          static int display_nickname = 0;
559    
560          SECTION_LIST *p_section;          SECTION_LIST *p_section;
561            int64_t section_index;
562            int32_t aid_location;
563          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
564          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
565          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 486  int section_list_display(const char *sna Line 575  int section_list_display(const char *sna
575          int direction;          int direction;
576          ARTICLE article_new;          ARTICLE article_new;
577          int page_id_cur;          int page_id_cur;
578            const ARTICLE *p_article_locate;
579            USER_INFO user_info;
580            char user_intro[BBS_user_intro_max_len];
581            char username[BBS_username_max_len + 1];
582            char username_list[1][BBS_username_max_len + 1];
583            int32_t uid;
584            int i;
585            int ok;
586    
587          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
588          if (p_section == NULL)          if (p_section == NULL)
# Line 494  int section_list_display(const char *sna Line 591  int section_list_display(const char *sna
591                  return -1;                  return -1;
592          }          }
593    
594          if ((ret = section_list_rd_lock(p_section)) < 0)          if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
595          {          {
596                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
597                  return -2;                                    p_section->sid, BBS_priv.uid);
598                    return -1;
599          }          }
600    
601          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';  
602    
603          if ((ret = section_list_rd_unlock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
604          {          {
605                  log_error("section_list_rd_unlock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
606                  return -2;                  return -4;
607            }
608    
609            if (aid == 0)
610            {
611                    aid_location = section_aid_locations[section_index];
612            }
613            else
614            {
615                    aid_location = aid;
616            }
617    
618            // Locate at article with aid_locate
619            if (aid_location > 0)
620            {
621                    p_article_locate = article_block_find_by_aid(aid_location);
622                    if (p_article_locate == NULL)
623                    {
624                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
625                            return -3;
626                    }
627    
628                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
629                                                                                    &page_id, &selected_index, &article_count);
630                    if (ret < 0)
631                    {
632                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
633                                              p_section->sid, p_article_locate->aid);
634                            return -3;
635                    }
636          }          }
637    
638          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
# Line 524  int section_list_display(const char *sna Line 648  int section_list_display(const char *sna
648                  return -3;                  return -3;
649          }          }
650    
651            section_topic_view_tid = -1;
652    
653          if (article_count == 0) // empty section          if (article_count == 0) // empty section
654          {          {
655                  selected_index = 0;                  selected_index = 0;
656          }          }
657            else if (aid > 0)
658            {
659                    // Update current topic
660                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
661    
662                    // Update current aid location
663                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
664            }
665    
666          while (!SYS_server_exit)          while (!SYS_server_exit)
667          {          {
# Line 551  int section_list_display(const char *sna Line 685  int section_list_display(const char *sna
685                  }                  }
686    
687                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
688    
689                  switch (ret)                  switch (ret)
690                  {                  {
691                  case EXIT_SECTION:                  case EXIT_SECTION:
692                            // Update current aid location
693                            if (p_articles[selected_index] != NULL)
694                            {
695                                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
696                            }
697                            else
698                            {
699                                    log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname);
700                            }
701                          return 0;                          return 0;
702                  case CHANGE_PAGE:                  case CHANGE_PAGE:
703                          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 829  int section_list_display(const char *sna Line 973  int section_list_display(const char *sna
973                                  return -2;                                  return -2;
974                          }                          }
975                          break;                          break;
976                    case QUERY_USER:
977                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)
978                            {
979                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
980                                    return -2;
981                            }
982                            else if (ret == 0)
983                            {
984                                    clearscr();
985                                    prints("该用户已升天");
986                                    press_any_key();
987                            }
988                            else if (user_info_display(&user_info) < 0) // && ret > 0
989                            {
990                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
991                            }
992    
993                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
994                            {
995                                    log_error("section_list_draw_screen() error\n");
996                                    return -2;
997                            }
998                            break;
999                    case SET_FAVOR_ARTICLE:
1000                            ret = article_favor_set(p_articles[selected_index]->tid == 0
1001                                                                                    ? p_articles[selected_index]->aid
1002                                                                                    : p_articles[selected_index]->tid,
1003                                                                            &BBS_article_favor, 1);
1004                            if (ret < 0)
1005                            {
1006                                    log_error("article_favor_set(aid=%d, 1) error\n",
1007                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
1008                            }
1009                            break;
1010                    case UNSET_FAVOR_ARTICLE:
1011                            ret = article_favor_set(p_articles[selected_index]->tid == 0
1012                                                                                    ? p_articles[selected_index]->aid
1013                                                                                    : p_articles[selected_index]->tid,
1014                                                                            &BBS_article_favor, 0);
1015                            if (ret < 0)
1016                            {
1017                                    log_error("article_favor_set(aid=%d, 0) error\n",
1018                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
1019                            }
1020                            break;
1021                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
1022                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
1023                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 851  int section_list_display(const char *sna Line 1040  int section_list_display(const char *sna
1040                                  }                                  }
1041                          }                          }
1042                          break;                          break;
1043                    case SCAN_NEW_ARTICLE:
1044                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
1045                            if (ret < 0)
1046                            {
1047                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
1048                                                      p_section->sid, p_articles[selected_index]->aid);
1049                                    return -3;
1050                            }
1051                            else if (ret == 0) // not found
1052                            {
1053                                    break;
1054                            }
1055                            page_id_cur = page_id;
1056                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1057                                                                                            &page_id, &selected_index, &article_count);
1058                            if (ret < 0)
1059                            {
1060                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1061                                                      p_section->sid, p_article_locate->aid);
1062                                    return -3;
1063                            }
1064                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1065                            {
1066                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1067                                    if (ret < 0)
1068                                    {
1069                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1070                                            return -3;
1071                                    }
1072                            }
1073                            break;
1074                    case SCAN_ARTICLE_BACKWARD_BY_USER:
1075                    case SCAN_ARTICLE_FORWARD_BY_USER:
1076                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_USER ? 1 : -1);
1077                            strncpy(username, p_articles[selected_index]->username, sizeof(username) - 1);
1078                            username[sizeof(username) - 1] = '\0';
1079                            uid = 0;
1080    
1081                            moveto(SCREEN_ROWS, 1);
1082                            clrtoeol();
1083                            get_data(SCREEN_ROWS, 1,
1084                                             (direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "),
1085                                             username, sizeof(username), BBS_username_max_len);
1086    
1087                            if (username[0] == '\0')
1088                            {
1089                                    break;
1090                            }
1091    
1092                            // Verify format
1093                            for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1094                            {
1095                                    if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))
1096                                    {
1097                                            ok = 0;
1098                                    }
1099                            }
1100                            if (ok && i > BBS_username_max_len)
1101                            {
1102                                    ok = 0;
1103                            }
1104                            if (!ok)
1105                            {
1106                                    break;
1107                            }
1108    
1109                            ret = query_user_info_by_username(username, 1, &uid, username_list);
1110                            if (ret < 0)
1111                            {
1112                                    log_error("query_user_info_by_username(%s) error\n", username);
1113                                    break;
1114                            }
1115    
1116                            if (uid > 0)
1117                            {
1118                                    ret = scan_article_in_section_by_uid(p_section, p_articles[selected_index],
1119                                                                                                             direction, uid, &p_article_locate);
1120                                    if (ret < 0)
1121                                    {
1122                                            log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n",
1123                                                              p_section->sid, p_articles[selected_index]->aid, direction, uid);
1124                                            return -3;
1125                                    }
1126                                    else if (ret == 0) // not found
1127                                    {
1128                                            break;
1129                                    }
1130                            }
1131                            else // uid == 0
1132                            {
1133                                    ret = scan_article_in_section_by_username(p_section, p_articles[selected_index],
1134                                                                                                                      direction, username, &p_article_locate);
1135                                    if (ret < 0)
1136                                    {
1137                                            log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n",
1138                                                              p_section->sid, p_articles[selected_index]->aid, direction, username);
1139                                            return -3;
1140                                    }
1141                                    else if (ret == 0) // not found
1142                                    {
1143                                            break;
1144                                    }
1145                            }
1146    
1147                            page_id_cur = page_id;
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\n",
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\n", p_section->sid, page_id);
1162                                            return -3;
1163                                    }
1164                            }
1165                            break;
1166                    case SEARCH_USER:
1167                            user_list_search();
1168                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1169                            {
1170                                    log_error("section_list_draw_screen() error\n");
1171                                    return -2;
1172                            }
1173                            break;
1174                  case SHOW_HELP:                  case SHOW_HELP:
1175                          // Display help information                          // Display help information
1176                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 871  int section_list_display(const char *sna Line 1191  int section_list_display(const char *sna
1191                                  return -2;                                  return -2;
1192                          }                          }
1193                          break;                          break;
1194                    case SHOW_TOP10:
1195                            show_top10_menu(NULL);
1196                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1197                            {
1198                                    log_error("section_list_draw_screen() error\n");
1199                                    return -2;
1200                            }
1201                            break;
1202                  default:                  default:
1203                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
1204                  }                  }
# Line 919  int section_list_ex_dir_display(SECTION_ Line 1247  int section_list_ex_dir_display(SECTION_
1247                  {                  {
1248                          iflush();                          iflush();
1249                          ch = igetch(100);                          ch = igetch(100);
1250    
1251                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1252                            {
1253                                    BBS_last_access_tm = time(NULL);
1254                            }
1255    
1256                          switch (ch)                          switch (ch)
1257                          {                          {
1258                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1259                                    log_error("KEY_NULL\n");
1260                                  return 0;                                  return 0;
1261                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1262                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1263                                  {                                  {
1264                                            log_error("User input timeout\n");
1265                                          return 0;                                          return 0;
1266                                  }                                  }
1267                                  continue;                                  continue;
1268                          case CR:                          case CR:
                                 igetch_reset();  
1269                          default:                          default:
1270                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1271                                  {                                  {
# Line 949  int section_list_ex_dir_display(SECTION_ Line 1284  int section_list_ex_dir_display(SECTION_
1284                                  }                                  }
1285                          }                          }
1286    
                         BBS_last_access_tm = time(NULL);  
   
1287                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1288                          {                          {
1289                                  break;                                  break;
# Line 962  int section_list_ex_dir_display(SECTION_ Line 1295  int section_list_ex_dir_display(SECTION_
1295    
1296          return 0;          return 0;
1297  }  }
1298    
1299    int section_aid_locations_save(int uid)
1300    {
1301            char filename[FILE_PATH_LEN];
1302            FILE *fp;
1303            int i;
1304            int ret = 0;
1305    
1306            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1307    
1308            if ((fp = fopen(filename, "wb")) == NULL)
1309            {
1310                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1311                    return -1;
1312            }
1313    
1314            for (i = 0; i < p_section_list_pool->section_count; i++)
1315            {
1316                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1317                    {
1318                            log_error("fwrite(%s, sid) error\n", filename);
1319                            ret = -2;
1320                            break;
1321                    }
1322    
1323                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1324                    {
1325                            log_error("fwrite(%s, aid) error\n", filename);
1326                            ret = -2;
1327                            break;
1328                    }
1329            }
1330    
1331            if (fclose(fp) < 0)
1332            {
1333                    log_error("fclose(%s) error: %d\n", filename, errno);
1334                    ret = -1;
1335            }
1336    
1337            return ret;
1338    }
1339    
1340    int section_aid_locations_load(int uid)
1341    {
1342            char filename[FILE_PATH_LEN];
1343            FILE *fp;
1344            int i;
1345            int32_t sid;
1346            int32_t aid;
1347            SECTION_LIST *p_section;
1348            int ret = 0;
1349    
1350            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1351    
1352            if ((fp = fopen(filename, "rb")) == NULL)
1353            {
1354                    if (errno == ENOENT) // file not exist
1355                    {
1356                            return 0;
1357                    }
1358                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1359                    return -1;
1360            }
1361    
1362            while (!feof(fp))
1363            {
1364                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1365                    {
1366                            if (ferror(fp) == 0)
1367                            {
1368                                    break;
1369                            }
1370                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1371                            ret = -2;
1372                            break;
1373                    }
1374    
1375                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1376                    {
1377                            if (ferror(fp) == 0)
1378                            {
1379                                    break;
1380                            }
1381                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1382                            ret = -2;
1383                            break;
1384                    }
1385    
1386                    p_section = section_list_find_by_sid(sid);
1387                    if (p_section == NULL)
1388                    {
1389                            continue; // skip section no longer exist
1390                    }
1391    
1392                    i = get_section_index(p_section);
1393                    if (i < 0)
1394                    {
1395                            log_error("get_section_index(sid=%d) error\n", sid);
1396                            ret = -3;
1397                            break;
1398                    }
1399                    section_aid_locations[i] = aid;
1400            }
1401    
1402            if (fclose(fp) < 0)
1403            {
1404                    log_error("fclose(%s) error: %d\n", filename, errno);
1405                    ret = -1;
1406            }
1407    
1408            return ret;
1409    }


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

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