/[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.52 by sysadm, Tue Oct 14 06:28:54 2025 UTC
# Line 24  Line 24 
24  #include "log.h"  #include "log.h"
25  #include "login.h"  #include "login.h"
26  #include "menu.h"  #include "menu.h"
27    #include "menu_proc.h"
28  #include "section_list_display.h"  #include "section_list_display.h"
29  #include "section_list_loader.h"  #include "section_list_loader.h"
30  #include "screen.h"  #include "screen.h"
# Line 33  Line 34 
34  #include <time.h>  #include <time.h>
35  #include <sys/param.h>  #include <sys/param.h>
36    
37    static int section_aid_locations[BBS_max_section] = {0};
38  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
39  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
40    
# Line 49  enum select_cmd_t Line 51  enum select_cmd_t
51          QUERY_ARTICLE,          QUERY_ARTICLE,
52          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
53          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
54            SCAN_NEW_ARTICLE,
55          VIEW_EX_DIR,          VIEW_EX_DIR,
56            SHOW_TOP10,
57  };  };
58    
59  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 132  static int section_list_draw_items(int p Line 136  static int section_list_draw_items(int p
136                  }                  }
137                  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)));
138    
139                  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);
140                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
141                  {                  {
142                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 291  static enum select_cmd_t section_list_se Line 295  static enum select_cmd_t section_list_se
295                                          (*p_page_id)--;                                          (*p_page_id)--;
296                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
297                                  }                                  }
298                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
299                                    {
300                                            if (total_page > 0)
301                                            {
302                                                    *p_page_id = total_page - 1;
303                                            }
304                                            if (item_count > 0)
305                                            {
306                                                    *p_selected_index = item_count - 1;
307                                            }
308                                    }
309                          }                          }
310                          else                          else
311                          {                          {
# Line 318  static enum select_cmd_t section_list_se Line 333  static enum select_cmd_t section_list_se
333                                          (*p_page_id)++;                                          (*p_page_id)++;
334                                          *p_selected_index = 0;                                          *p_selected_index = 0;
335                                  }                                  }
336                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
337                                  {                                  {
338                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
339                                            *p_selected_index = 0;
340                                  }                                  }
341                          }                          }
342                          else                          else
# Line 340  static enum select_cmd_t section_list_se Line 356  static enum select_cmd_t section_list_se
356                                  return LAST_TOPIC_ARTICLE;                                  return LAST_TOPIC_ARTICLE;
357                          }                          }
358                          break;                          break;
359                    case 'S':
360                            if (item_count > 0)
361                            {
362                                    return SCAN_NEW_ARTICLE;
363                            }
364                            break;
365                  case 'h':                  case 'h':
366                          return SHOW_HELP;                          return SHOW_HELP;
367                  case 'x':                  case 'x':
368                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
369                    case 'H':
370                            return SHOW_TOP10;
371                  default:                  default:
372                  }                  }
373    
# Line 466  static int display_article_key_handler(i Line 490  static int display_article_key_handler(i
490          return 0;          return 0;
491  }  }
492    
493  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
494  {  {
495          static int display_nickname = 0;          static int display_nickname = 0;
496    
497          SECTION_LIST *p_section;          SECTION_LIST *p_section;
498            int64_t section_index;
499            int32_t aid_location;
500          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
501          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
502          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 486  int section_list_display(const char *sna Line 512  int section_list_display(const char *sna
512          int direction;          int direction;
513          ARTICLE article_new;          ARTICLE article_new;
514          int page_id_cur;          int page_id_cur;
515            const ARTICLE *p_article_locate;
516    
517          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
518          if (p_section == NULL)          if (p_section == NULL)
# Line 494  int section_list_display(const char *sna Line 521  int section_list_display(const char *sna
521                  return -1;                  return -1;
522          }          }
523    
524            if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
525            {
526                    log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
527                                      p_section->sid, BBS_priv.uid);
528                    return -1;
529            }
530    
531            section_index = get_section_index(p_section);
532    
533          if ((ret = section_list_rd_lock(p_section)) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
534          {          {
535                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("section_list_rd_lock(sid = 0) error\n");
# Line 511  int section_list_display(const char *sna Line 547  int section_list_display(const char *sna
547                  return -2;                  return -2;
548          }          }
549    
550            if (aid == 0)
551            {
552                    aid_location = section_aid_locations[section_index];
553            }
554            else
555            {
556                    aid_location = aid;
557            }
558    
559            // Locate at article with aid_locate
560            if (aid_location > 0)
561            {
562                    p_article_locate = article_block_find_by_aid(aid_location);
563                    if (p_article_locate == NULL)
564                    {
565                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
566                            return -3;
567                    }
568    
569                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
570                                                                                    &page_id, &selected_index, &article_count);
571                    if (ret < 0)
572                    {
573                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
574                                              p_section->sid, p_article_locate->aid);
575                            return -3;
576                    }
577            }
578    
579          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
580          {          {
581                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
# Line 524  int section_list_display(const char *sna Line 589  int section_list_display(const char *sna
589                  return -3;                  return -3;
590          }          }
591    
592            section_topic_view_tid = -1;
593    
594          if (article_count == 0) // empty section          if (article_count == 0) // empty section
595          {          {
596                  selected_index = 0;                  selected_index = 0;
597          }          }
598            else if (aid > 0)
599            {
600                    // Update current topic
601                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
602    
603                    // Update current aid location
604                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
605            }
606    
607          while (!SYS_server_exit)          while (!SYS_server_exit)
608          {          {
# Line 732  int section_list_display(const char *sna Line 807  int section_list_display(const char *sna
807                          // Update current topic                          // Update current topic
808                          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);
809    
810                            // Update current aid location
811                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
812    
813                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
814                          {                          {
815                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 851  int section_list_display(const char *sna Line 929  int section_list_display(const char *sna
929                                  }                                  }
930                          }                          }
931                          break;                          break;
932                    case SCAN_NEW_ARTICLE:
933                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
934                            if (ret < 0)
935                            {
936                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
937                                                      p_section->sid, p_articles[selected_index]->aid);
938                                    return -3;
939                            }
940                            else if (ret == 0) // not found
941                            {
942                                    break;
943                            }
944                            page_id_cur = page_id;
945                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
946                                                                                            &page_id, &selected_index, &article_count);
947                            if (ret < 0)
948                            {
949                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
950                                                      p_section->sid, p_article_locate->aid);
951                                    return -3;
952                            }
953                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
954                            {
955                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
956                                    if (ret < 0)
957                                    {
958                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
959                                            return -3;
960                                    }
961                            }
962                            break;
963                  case SHOW_HELP:                  case SHOW_HELP:
964                          // Display help information                          // Display help information
965                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 868  int section_list_display(const char *sna Line 977  int section_list_display(const char *sna
977                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
978                          {                          {
979                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
980                                    return -2;
981                            }
982                            break;
983                    case SHOW_TOP10:
984                            show_top10_menu(NULL);
985                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
986                            {
987                                    log_error("section_list_draw_screen() error\n");
988                                  return -2;                                  return -2;
989                          }                          }
990                          break;                          break;


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

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