/[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.38 by sysadm, Thu Jun 26 12:17:02 2025 UTC Revision 1.52 by sysadm, Tue Oct 21 06:24:51 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_view_log.h"
19  #include "bbs.h"  #include "bbs.h"
20  #include "database.h"  #include "database.h"
21    #include "ip_mask.h"
22  #include "log.h"  #include "log.h"
23  #include "menu.h"  #include "menu.h"
24  #include "section_list_loader.h"  #include "section_list_loader.h"
25    #include "user_list.h"
26    #include "user_priv.h"
27  #include <errno.h>  #include <errno.h>
28  #include <signal.h>  #include <signal.h>
29  #include <stdio.h>  #include <stdio.h>
# Line 134  int load_section_config_from_db(int upda Line 138  int load_section_config_from_db(int upda
138                                  break;                                  break;
139                          }                          }
140    
141                          strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1);                          if (section_list_update(p_section, row[1], row[2], master_list) < 0)
142                          p_section->sname[sizeof(p_section->sname) - 1] = '\0';                          {
143                          strncpy(p_section->stitle, row[2], sizeof(p_section->stitle) - 1);                                  log_error("section_list_update(sid=%d) error\n", p_section->sid);
144                          p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';                                  ret = -4;
145                          strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1);                                  break;
146                          p_section->master_list[sizeof(p_section->master_list) - 1] = '\0';                          }
147                  }                  }
148    
149                  p_section->class_id = atoi(row[3]);                  p_section->class_id = atoi(row[3]);
# Line 148  int load_section_config_from_db(int upda Line 152  int load_section_config_from_db(int upda
152                  p_section->enable = (int8_t)atoi(row[6]);                  p_section->enable = (int8_t)atoi(row[6]);
153    
154                  // Update gen_ex menu set                  // Update gen_ex menu set
155                  if (update_gen_ex && p_section->enable && atoi(row[7]) > p_section->ex_menu_tm)                  if (update_gen_ex && p_section->enable && atol(row[7] == NULL ? "0" : row[7]) > p_section->ex_menu_tm)
156                  {                  {
157                          snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid);                          snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid);
158    
# Line 664  cleanup: Line 668  cleanup:
668          return (ret < 0 ? ret : op_count);          return (ret < 0 ? ret : op_count);
669  }  }
670    
671    static void section_list_ex_menu_set_cleanup(void)
672    {
673            int i;
674    
675            for (i = 0; i < p_section_list_pool->section_count; i++)
676            {
677                    if (p_section_list_pool->sections[i].ex_menu_tm > 0)
678                    {
679                            unload_menu(&(p_section_list_pool->sections[i].ex_menu_set));
680                    }
681            }
682    }
683    
684  int section_list_loader_launch(void)  int section_list_loader_launch(void)
685  {  {
686          struct sigaction act = {0};          struct sigaction act = {0};
# Line 673  int section_list_loader_launch(void) Line 690  int section_list_loader_launch(void)
690          int article_count;          int article_count;
691          int load_count;          int load_count;
692          int last_mid;          int last_mid;
693          int i;          time_t tm_section_list_reload = 0;
694            time_t tm_user_list_reload = 0;
695    
696          if (section_list_loader_pid != 0)          if (section_list_loader_pid != 0)
697          {          {
# Line 701  int section_list_loader_launch(void) Line 719  int section_list_loader_launch(void)
719    
720          // Detach menu in shared memory          // Detach menu in shared memory
721          detach_menu_shm(&bbs_menu);          detach_menu_shm(&bbs_menu);
722            detach_menu_shm(&top10_menu);
723    
724          // Set signal handler          // Set signal handler
725          act.sa_handler = SIG_DFL;          act.sa_handler = SIG_DFL;
# Line 717  int section_list_loader_launch(void) Line 736  int section_list_loader_launch(void)
736          // Do section data loader periodically          // Do section data loader periodically
737          while (!SYS_server_exit)          while (!SYS_server_exit)
738          {          {
739                    tm_section_list_reload = time(NULL);
740    
741                  if (SYS_conf_reload)                  if (SYS_conf_reload)
742                  {                  {
743                          SYS_conf_reload = 0;                          SYS_conf_reload = 0;
# Line 782  int section_list_loader_launch(void) Line 803  int section_list_loader_launch(void)
803                          log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid);                          log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid);
804                  }                  }
805    
806                  if (SYS_conf_reload)                  // Reload user list
807                    if (time(NULL) - tm_user_list_reload >= BBS_user_list_load_interval)
808                  {                  {
809                          continue;                          if (user_list_pool_reload() < 0)
810                            {
811                                    log_error("user_list_pool_reload() error\n");
812                            }
813                            tm_user_list_reload = time(NULL);
814                  }                  }
815    
816                  for (i = 0; i < BBS_section_list_load_interval && !SYS_server_exit && !SYS_conf_reload; i++)                  // Wait for BBS_section_list_load_interval seconds
817                    while (!SYS_server_exit && time(NULL) - tm_section_list_reload < BBS_section_list_load_interval)
818                  {                  {
819                          sleep(1);                          sleep(1);
820                  }                  }
# Line 804  int section_list_loader_launch(void) Line 831  int section_list_loader_launch(void)
831          detach_section_list_shm();          detach_section_list_shm();
832          detach_article_block_shm();          detach_article_block_shm();
833          detach_trie_dict_shm();          detach_trie_dict_shm();
834            detach_user_list_pool_shm();
835    
836          log_common("Section list loader process exit normally\n");          log_common("Section list loader process exit normally\n");
837          log_end();          log_end();
# Line 904  int locate_article_in_section(SECTION_LI Line 932  int locate_article_in_section(SECTION_LI
932                                                            int *p_page_id, int *p_visible_offset, int *p_article_count)                                                            int *p_page_id, int *p_visible_offset, int *p_article_count)
933  {  {
934          const ARTICLE *p_article = NULL;          const ARTICLE *p_article = NULL;
935            const ARTICLE *p_article_last = NULL;
936          ARTICLE *p_tmp;          ARTICLE *p_tmp;
937          int32_t aid = 0;          int32_t aid = 0;
938          int page_id = 0;          int page_id = 0;
# Line 930  int locate_article_in_section(SECTION_LI Line 959  int locate_article_in_section(SECTION_LI
959          }          }
960          else if (direction == 1)          else if (direction == 1)
961          {          {
962                  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)                  for (p_article_last = p_article_cur, p_article = p_article_cur->p_topic_next;
963                             step > 0 && p_article->aid > p_article_cur->aid;
964                             p_article = p_article->p_topic_next)
965                  {                  {
966                          if (p_article->visible)                          if (p_article->visible)
967                          {                          {
968                                  step--;                                  step--;
969                                    p_article_last = p_article;
970                          }                          }
971                  }                  }
972                    p_article = p_article_last;
973    
974                  aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0);                  aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0);
975          }          }
976          else if (direction == -1)          else if (direction == -1)
977          {          {
978                  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)                  for (p_article_last = p_article_cur, p_article = p_article_cur->p_topic_prior;
979                             step > 0 && p_article->aid < p_article_cur->aid;
980                             p_article = p_article->p_topic_prior)
981                  {                  {
982                          if (p_article->visible)                          if (p_article->visible)
983                          {                          {
984                                  step--;                                  step--;
985                                    p_article_last = p_article;
986                          }                          }
987                  }                  }
988                    p_article = p_article_last;
989    
990                  aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0);                  aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0);
991          }          }
# Line 999  int locate_article_in_section(SECTION_LI Line 1036  int locate_article_in_section(SECTION_LI
1036          return (ret < 0 ? ret : (p_article == NULL ? 0 : 1));          return (ret < 0 ? ret : (p_article == NULL ? 0 : 1));
1037  }  }
1038    
1039    int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, const ARTICLE **pp_article_unread)
1040    {
1041            ARTICLE *p_article;
1042            int ret = 0;
1043    
1044            if (p_section == NULL || p_article_cur == NULL || pp_article_unread == NULL)
1045            {
1046                    log_error("NULL pointer error\n");
1047                    return -1;
1048            }
1049    
1050            if (p_article_cur->sid != p_section->sid)
1051            {
1052                    log_error("Inconsistent SID\n");
1053                    return -1;
1054            }
1055    
1056            // acquire lock of section
1057            if ((ret = section_list_rd_lock(p_section)) < 0)
1058            {
1059                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1060                    return -2;
1061            }
1062    
1063            *pp_article_unread = NULL;
1064    
1065            for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1066            {
1067                    if (p_article->visible && p_article->uid != BBS_priv.uid && !article_view_log_is_viewed(p_article->aid, &BBS_article_view_log))
1068                    {
1069                            *pp_article_unread = p_article;
1070                            break;
1071                    }
1072            }
1073    
1074            // release lock of section
1075            if (section_list_rd_unlock(p_section) < 0)
1076            {
1077                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1078                    return -2;
1079            }
1080    
1081            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1082    }
1083    
1084  int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set)  int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set)
1085  {  {
1086          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