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

Diff of /lbbs/src/section_list_loader.c

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

Revision 1.59 by sysadm, Mon Nov 3 08:48:56 2025 UTC Revision 1.65 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          section_list_loader.c  -  description  /*
3                                                           -------------------   * section_list_loader
4          Copyright            : (C) 2004-2025 by Leaflet   *   - load and query operations of section articles
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "article_view_log.h"  #include "article_view_log.h"
# Line 892  int query_section_articles(SECTION_LIST Line 888  int query_section_articles(SECTION_LIST
888          }          }
889          else if (page_id < 0 || page_id >= *p_page_count)          else if (page_id < 0 || page_id >= *p_page_count)
890          {          {
891    #ifdef _DEBUG
892                  log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, *p_page_count);                  log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, *p_page_count);
893    #endif
894                  ret = -3;                  ret = -3;
895          }          }
896          else          else
# Line 1016  int locate_article_in_section(SECTION_LI Line 1014  int locate_article_in_section(SECTION_LI
1014                  p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp);                  p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp);
1015                  if (p_article != NULL)                  if (p_article != NULL)
1016                  {                  {
1017                          *p_article_count = (page_id == p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page);                          *p_article_count = (page_id >= p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page);
1018    
1019                          p_article = p_section->p_page_first_article[page_id];                          p_article = p_section->p_page_first_article[page_id];
1020                          for (i = 0; i < *p_article_count && p_article != NULL;)                          for (i = 0; i < *p_article_count && p_article != NULL;)
# Line 1037  int locate_article_in_section(SECTION_LI Line 1035  int locate_article_in_section(SECTION_LI
1035                                                  break;                                                  break;
1036                                          }                                          }
1037                                  }                                  }
1038    
1039                                  p_article = p_article->p_next;                                  p_article = p_article->p_next;
1040                                    if (p_article == p_section->p_page_first_article[page_id])
1041                                    {
1042                                            log_error("Dead loop detected at page=%d, article_count=%d\n", page_id, *p_article_count);
1043                                            break;
1044                                    }
1045                          }                          }
1046    
1047                          // Include ontop articles                          // Include ontop articles
# Line 1055  int locate_article_in_section(SECTION_LI Line 1059  int locate_article_in_section(SECTION_LI
1059          return (ret < 0 ? ret : (p_article == NULL ? 0 : 1));          return (ret < 0 ? ret : (p_article == NULL ? 0 : 1));
1060  }  }
1061    
1062    int last_article_in_section(SECTION_LIST *p_section, const ARTICLE **pp_article)
1063    {
1064            int ret = 0;
1065    
1066            const ARTICLE *p_article;
1067    
1068            if (p_section == NULL || pp_article == NULL)
1069            {
1070                    log_error("NULL pointer error\n");
1071                    return -1;
1072            }
1073    
1074            *pp_article = NULL;
1075    
1076            // acquire lock of section
1077            if ((ret = section_list_rd_lock(p_section)) < 0)
1078            {
1079                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1080                    return -2;
1081            }
1082    
1083            for (p_article = p_section->p_article_tail;
1084                     p_article && p_article != p_section->p_article_head && !p_article->visible;
1085                     p_article = p_article->p_prior)
1086                    ;
1087    
1088            if (p_article && p_article->visible)
1089            {
1090                    *pp_article = p_article;
1091                    ret = 1;
1092            }
1093    
1094            // release lock of section
1095            if (section_list_rd_unlock(p_section) < 0)
1096            {
1097                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1098                    ret = -2;
1099            }
1100    
1101            return ret;
1102    }
1103    
1104  int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, const ARTICLE **pp_article_unread)  int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, const ARTICLE **pp_article_unread)
1105  {  {
1106          ARTICLE *p_article;          ARTICLE *p_article;
# Line 1221  int scan_article_in_section_by_username( Line 1267  int scan_article_in_section_by_username(
1267  }  }
1268    
1269  int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_article_cur,  int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_article_cur,
1270                                                                                  int direction, const char *title, const ARTICLE **pp_article)                                                                           int direction, const char *title, const ARTICLE **pp_article)
1271  {  {
1272          ARTICLE *p_article;          ARTICLE *p_article;
1273          int ret = 0;          int ret = 0;


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

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