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

Diff of /lbbs/src/section_list.c

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

Revision 1.37 by sysadm, Wed Jun 25 02:49:20 2025 UTC Revision 1.46 by sysadm, Thu Oct 23 05:54:16 2025 UTC
# Line 17  Line 17 
17  #include "log.h"  #include "log.h"
18  #include "section_list.h"  #include "section_list.h"
19  #include "trie_dict.h"  #include "trie_dict.h"
20    #include "user_list.h"
21  #include <errno.h>  #include <errno.h>
22  #include <signal.h>  #include <signal.h>
23  #include <stdio.h>  #include <stdio.h>
# Line 75  typedef struct article_block_pool_t ARTI Line 76  typedef struct article_block_pool_t ARTI
76    
77  static ARTICLE_BLOCK_POOL *p_article_block_pool = NULL;  static ARTICLE_BLOCK_POOL *p_article_block_pool = NULL;
78    
79  struct section_list_pool_t  SECTION_LIST_POOL *p_section_list_pool = NULL;
 {  
         int shmid;  
         SECTION_LIST sections[BBS_max_section];  
         int section_count;  
         int semid;  
         TRIE_NODE *p_trie_dict_section_by_name;  
         TRIE_NODE *p_trie_dict_section_by_sid;  
 };  
 typedef struct section_list_pool_t SECTION_LIST_POOL;  
   
 static SECTION_LIST_POOL *p_section_list_pool = NULL;  
80    
81  int article_block_init(const char *filename, int block_count)  int article_block_init(const char *filename, int block_count)
82  {  {
# Line 555  void section_list_cleanup(void) Line 545  void section_list_cleanup(void)
545          p_section_list_pool = NULL;          p_section_list_pool = NULL;
546  }  }
547    
 void section_list_ex_menu_set_cleanup(void)  
 {  
         int i;  
   
         for (i = 0; i < p_section_list_pool->section_count; i++)  
         {  
                 if (p_section_list_pool->sections[i].ex_menu_tm > 0)  
                 {  
                         unload_menu(&(p_section_list_pool->sections[i].ex_menu_set));  
                 }  
         }  
 }  
   
548  int set_section_list_shm_readonly(void)  int set_section_list_shm_readonly(void)
549  {  {
550          int shmid;          int shmid;
# Line 673  SECTION_LIST *section_list_create(int32_ Line 650  SECTION_LIST *section_list_create(int32_
650          return p_section;          return p_section;
651  }  }
652    
653    int section_list_update(SECTION_LIST *p_section, const char *sname, const char *stitle, const char *master_list)
654    {
655            int64_t index;
656    
657            if (p_section == NULL || sname == NULL || stitle == NULL || master_list == NULL)
658            {
659                    log_error("NULL pointer error\n");
660                    return -1;
661            }
662    
663            index = get_section_index(p_section);
664    
665            strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1);
666            p_section->sname[sizeof(p_section->sname) - 1] = '\0';
667    
668            strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1);
669            p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';
670    
671            strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1);
672            p_section->master_list[sizeof(p_section->master_list) - 1] = '\0';
673    
674            if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, index) < 0)
675            {
676                    log_error("trie_dict_set(section, %s, %d) error\n", sname, index);
677                    return -2;
678            }
679    
680            return 0;
681    }
682    
683  void section_list_reset_articles(SECTION_LIST *p_section)  void section_list_reset_articles(SECTION_LIST *p_section)
684  {  {
685          p_section->article_count = 0;          p_section->article_count = 0;
# Line 751  int section_list_append_article(SECTION_ Line 758  int section_list_append_article(SECTION_
758    
759          if (p_section == NULL || p_article_src == NULL)          if (p_section == NULL || p_article_src == NULL)
760          {          {
761                  log_error("section_list_append_article() NULL pointer error\n");                  log_error("NULL pointer error\n");
762                  return -1;                  return -1;
763          }          }
764    
# Line 919  int section_list_set_article_visible(SEC Line 926  int section_list_set_article_visible(SEC
926          {          {
927                  p_section->visible_article_count--;                  p_section->visible_article_count--;
928    
929                    if (user_article_cnt_inc(p_article->uid, -1) < 0)
930                    {
931                            log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_article->uid);
932                    }
933    
934                  if (p_article->tid == 0)                  if (p_article->tid == 0)
935                  {                  {
936                          p_section->visible_topic_count--;                          p_section->visible_topic_count--;
# Line 937  int section_list_set_article_visible(SEC Line 949  int section_list_set_article_visible(SEC
949                                          p_reply->visible = 0;                                          p_reply->visible = 0;
950                                          p_section->visible_article_count--;                                          p_section->visible_article_count--;
951                                          affected_count++;                                          affected_count++;
952    
953                                            if (user_article_cnt_inc(p_reply->uid, -1) < 0)
954                                            {
955                                                    log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_reply->uid);
956                                            }
957                                  }                                  }
958                          }                          }
959                  }                  }
# Line 949  int section_list_set_article_visible(SEC Line 966  int section_list_set_article_visible(SEC
966                  {                  {
967                          p_section->visible_topic_count++;                          p_section->visible_topic_count++;
968                  }                  }
969    
970                    if (user_article_cnt_inc(p_article->uid, 1) < 0)
971                    {
972                            log_error("user_article_cnt_inc(uid=%d, 1) error\n", p_article->uid);
973                    }
974          }          }
975    
976          p_article->visible = visible;          p_article->visible = visible;
# Line 1047  int section_list_page_count_with_ontop(S Line 1069  int section_list_page_count_with_ontop(S
1069                  return -1;                  return -1;
1070          }          }
1071    
1072          page_count = p_section->page_count - 1 +          page_count = p_section->page_count - (p_section->last_page_visible_article_count > 0 ? 1 : 0) +
1073                                   (p_section->last_page_visible_article_count + p_section->ontop_article_count) / BBS_article_limit_per_page +                                   (p_section->last_page_visible_article_count + p_section->ontop_article_count) / BBS_article_limit_per_page +
1074                                   ((p_section->last_page_visible_article_count + p_section->ontop_article_count) % BBS_article_limit_per_page == 0 ? 0 : 1);                                   ((p_section->last_page_visible_article_count + p_section->ontop_article_count) % BBS_article_limit_per_page == 0 ? 0 : 1);
1075    
# Line 1086  ARTICLE *section_list_find_article_with_ Line 1108  ARTICLE *section_list_find_article_with_
1108    
1109          if (p_section == NULL)          if (p_section == NULL)
1110          {          {
1111                  log_error("section_list_find_article_with_offset() NULL pointer error\n");                  log_error("NULL pointer error\n");
1112                  return NULL;                  return NULL;
1113          }          }
1114    
# Line 1178  int section_list_calculate_page(SECTION_ Line 1200  int section_list_calculate_page(SECTION_
1200    
1201          if (p_section == NULL)          if (p_section == NULL)
1202          {          {
1203                  log_error("section_list_calculate_page() NULL pointer error\n");                  log_error("NULL pointer error\n");
1204                  return -1;                  return -1;
1205          }          }
1206    
# Line 1337  int section_list_move_topic(SECTION_LIST Line 1359  int section_list_move_topic(SECTION_LIST
1359    
1360          if (p_section_src == NULL || p_section_dest == NULL)          if (p_section_src == NULL || p_section_dest == NULL)
1361          {          {
1362                  log_error("section_list_move_topic() NULL pointer error\n");                  log_error("NULL pointer error\n");
1363                  return -1;                  return -1;
1364          }          }
1365    
# Line 1709  int section_list_rd_lock(SECTION_LIST *p Line 1731  int section_list_rd_lock(SECTION_LIST *p
1731                          timer++;                          timer++;
1732                          if (timer % SECTION_TRY_LOCK_TIMES == 0)                          if (timer % SECTION_TRY_LOCK_TIMES == 0)
1733                          {                          {
1734                                  log_error("section_list_try_rd_lock() tried %d times on section %d\n", sid, timer);                                  log_error("section_list_try_rd_lock() tried %d times on section %d\n", timer, sid);
1735                          }                          }
1736                  }                  }
1737                  else // failed                  else // failed
# Line 1740  int section_list_rw_lock(SECTION_LIST *p Line 1762  int section_list_rw_lock(SECTION_LIST *p
1762                          timer++;                          timer++;
1763                          if (timer % SECTION_TRY_LOCK_TIMES == 0)                          if (timer % SECTION_TRY_LOCK_TIMES == 0)
1764                          {                          {
1765                                  log_error("section_list_try_rw_lock() tried %d times on section %d\n", sid, timer);                                  log_error("section_list_try_rw_lock() tried %d times on section %d\n", timer, sid);
1766                          }                          }
1767                  }                  }
1768                  else // failed                  else // failed


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

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