/[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.23 by sysadm, Mon Jun 16 14:33:48 2025 UTC Revision 1.31 by sysadm, Sat Jun 21 06:52:24 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
 #define _POSIX_C_SOURCE 200809L  
   
 #include "section_list_loader.h"  
17  #include "article_cache.h"  #include "article_cache.h"
18  #include "bbs.h"  #include "bbs.h"
 #include "log.h"  
19  #include "database.h"  #include "database.h"
20    #include "log.h"
21  #include "menu.h"  #include "menu.h"
22  #include <stdio.h>  #include "section_list_loader.h"
 #include <string.h>  
23  #include <errno.h>  #include <errno.h>
24  #include <signal.h>  #include <signal.h>
25    #include <stdio.h>
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <string.h>  #include <string.h>
 #include <strings.h>  
28  #include <unistd.h>  #include <unistd.h>
29    
30  int section_list_loader_pid;  int section_list_loader_pid;
# Line 135  int load_section_config_from_db(void) Line 131  int load_section_config_from_db(void)
131                                  break;                                  break;
132                          }                          }
133    
134                          strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1);                          strncpy(p_section->sname, row[0], sizeof(p_section->sname) - 1);
135                          p_section->sname[sizeof(p_section->sname) - 1] = '\0';                          p_section->sname[sizeof(p_section->sname) - 1] = '\0';
136                          strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1);                          strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1);
137                          p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';                          p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';
# Line 157  int load_section_config_from_db(void) Line 153  int load_section_config_from_db(void)
153          }          }
154    
155  cleanup:  cleanup:
156            mysql_free_result(rs2);
157          mysql_free_result(rs);          mysql_free_result(rs);
158          mysql_close(db);          mysql_close(db);
159    
# Line 324  cleanup: Line 321  cleanup:
321          mysql_free_result(rs);          mysql_free_result(rs);
322          mysql_close(db);          mysql_close(db);
323    
324            article_cache_cleanup();
325    
326          return (ret < 0 ? ret : article_count);          return (ret < 0 ? ret : article_count);
327  }  }
328    
# Line 684  int section_list_loader_launch(void) Line 683  int section_list_loader_launch(void)
683                          }                          }
684                          else                          else
685                          {                          {
686                                  log_error("Reload section config successfully\n");                                  log_common("Reload section config successfully\n");
687                          }                          }
688                  }                  }
689    
# Line 751  int section_list_loader_launch(void) Line 750  int section_list_loader_launch(void)
750    
751          // Child process exit          // Child process exit
752    
753            article_cache_cleanup();
754    
755          // Detach data pools shm          // Detach data pools shm
756          detach_section_list_shm();          detach_section_list_shm();
757          detach_article_block_shm();          detach_article_block_shm();
# Line 847  int query_section_articles(SECTION_LIST Line 848  int query_section_articles(SECTION_LIST
848          return ret;          return ret;
849  }  }
850    
851  int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction,  int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction, int step,
852                                                            int *p_page_id, int *p_visible_offset, int *p_article_count)                                                            int *p_page_id, int *p_visible_offset, int *p_article_count)
853  {  {
854          const ARTICLE *p_article = NULL;          const ARTICLE *p_article = NULL;
855          ARTICLE *p_tmp;          ARTICLE *p_tmp;
856          int32_t aid = 0;          int32_t aid = 0;
857          int page_id;          int page_id = 0;
858          int offset;          int offset = 0;
859          int ret = 0;          int ret = 0;
860          int i;          int i;
861    
# Line 877  int locate_article_in_section(SECTION_LI Line 878  int locate_article_in_section(SECTION_LI
878          }          }
879          else if (direction == 1)          else if (direction == 1)
880          {          {
881                  p_article = p_article_cur;                  for (p_article = p_article_cur; step > 0 && p_article->p_topic_next->aid > p_article_cur->aid; p_article = p_article->p_topic_next)
                 do  
882                  {                  {
883                          p_article = p_article->p_topic_next;                          if (p_article->visible)
884                  } while (p_article != p_article_cur && p_article->visible == 0);                          {
885                                    step--;
886                            }
887                    }
888    
889                  aid = (p_article->aid > p_article_cur->aid ? p_article->aid : 0);                  aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0);
890          }          }
891          else if (direction == -1)          else if (direction == -1)
892          {          {
893                  p_article = p_article_cur;                  for (p_article = p_article_cur; step > 0 && p_article->p_topic_prior->aid < p_article_cur->aid; p_article = p_article->p_topic_prior)
                 do  
894                  {                  {
895                          p_article = p_article->p_topic_prior;                          if (p_article->visible)
896                  } while (p_article != p_article_cur && p_article->visible == 0);                          {
897                                    step--;
898                            }
899                    }
900    
901                  aid = (p_article->aid < p_article_cur->aid ? p_article->aid : 0);                  aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0);
902          }          }
903    
904          p_article = NULL;          p_article = NULL;
# Line 906  int locate_article_in_section(SECTION_LI Line 911  int locate_article_in_section(SECTION_LI
911                          *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);
912    
913                          p_article = p_section->p_page_first_article[page_id];                          p_article = p_section->p_page_first_article[page_id];
914                          for (i = 0; i < *p_article_count;)                          for (i = 0; i < *p_article_count && p_article != NULL;)
915                          {                          {
916                                  if (p_article->visible)                                  if (p_article->visible)
917                                  {                                  {
# Line 921  int locate_article_in_section(SECTION_LI Line 926  int locate_article_in_section(SECTION_LI
926                                          {                                          {
927                                                  log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id);                                                  log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id);
928                                                  p_article = NULL;                                                  p_article = NULL;
929                                                    break;
930                                          }                                          }
931                                  }                                  }
932                                  p_article = p_article->p_next;                                  p_article = p_article->p_next;


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

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