/[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.1 by sysadm, Wed May 21 04:07:42 2025 UTC Revision 1.3 by sysadm, Wed May 21 06:17:52 2025 UTC
# Line 27  Line 27 
27  #include <sys/shm.h>  #include <sys/shm.h>
28  #include <sys/ipc.h>  #include <sys/ipc.h>
29    
30    // ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT should be
31    // no less than BBS_article_block_limit_per_section * BBS_max_section,
32    // in order to allocate enough memory for blocks
33  #define ARTICLE_BLOCK_PER_SHM 50 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate  #define ARTICLE_BLOCK_PER_SHM 50 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate
34  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 256  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 256 // limited by length (8-bit) of proj_id in ftok(path, proj_id)
35    
36  struct article_block_shm_t  struct article_block_shm_t
37  {  {
# Line 380  int section_data_append_article(SECTION_ Line 383  int section_data_append_article(SECTION_
383    
384          if (p_article->tid != 0)          if (p_article->tid != 0)
385          {          {
386                  p_topic_head = section_data_search_article(p_section, p_article->tid);                  p_topic_head = section_data_find_article_by_aid(p_section, p_article->tid);
387                  if (p_topic_head == NULL)                  if (p_topic_head == NULL)
388                  {                  {
389                          log_error("search head of topic (aid=%d) error\n", p_article->tid);                          log_error("search head of topic (aid=%d) error\n", p_article->tid);
390                          return -4;                          return -4;
391                  }                  }
392    
393                  p_topic_tail = section_data_search_article(p_section, p_topic_head->prior_aid);                  p_topic_tail = section_data_find_article_by_aid(p_section, p_topic_head->prior_aid);
394                  if (p_topic_tail == NULL)                  if (p_topic_tail == NULL)
395                  {                  {
396                          log_error("search tail of topic (aid=%d) error\n", p_topic_head->prior_aid);                          log_error("search tail of topic (aid=%d) error\n", p_topic_head->prior_aid);
# Line 415  int section_data_append_article(SECTION_ Line 418  int section_data_append_article(SECTION_
418          return 0;          return 0;
419  }  }
420    
421  ARTICLE *section_data_search_article(SECTION_DATA *p_section, int32_t aid)  ARTICLE *section_data_find_article_by_aid(SECTION_DATA *p_section, int32_t aid)
422  {  {
423          ARTICLE *p_article;          ARTICLE *p_article;
424          ARTICLE_BLOCK *p_block;          ARTICLE_BLOCK *p_block;
# Line 425  ARTICLE *section_data_search_article(SEC Line 428  ARTICLE *section_data_search_article(SEC
428    
429          if (p_section == NULL)          if (p_section == NULL)
430          {          {
431                  log_error("section_data_append_article() NULL pointer error\n");                  log_error("section_data_find_article_by_aid() NULL pointer error\n");
432                  return NULL;                  return NULL;
433          }          }
434    
# Line 484  ARTICLE *section_data_search_article(SEC Line 487  ARTICLE *section_data_search_article(SEC
487          return p_article;          return p_article;
488  }  }
489    
490    ARTICLE *section_data_find_article_by_index(SECTION_DATA *p_section, int index)
491    {
492            ARTICLE *p_article;
493            ARTICLE_BLOCK *p_block;
494    
495            if (p_section == NULL)
496            {
497                    log_error("section_data_find_article_by_index() NULL pointer error\n");
498                    return NULL;
499            }
500    
501            if (index < 0 || index >= p_section->article_count)
502            {
503                    log_error("section_data_find_article_by_index(%d) is out of boundary [0, %d)\n", index, p_section->article_count);
504                    return NULL;
505            }
506    
507            p_block = p_section->p_block[index / BBS_article_limit_per_block];
508            p_article = &(p_block->articles[index % BBS_article_limit_per_block]);
509    
510            return p_article;
511    }
512    
513  int section_data_mark_del_article(SECTION_DATA *p_section, int32_t aid)  int section_data_mark_del_article(SECTION_DATA *p_section, int32_t aid)
514  {  {
515          ARTICLE *p_article;          ARTICLE *p_article;
516    
517          p_article = section_data_search_article(p_section, aid);          if (p_section == NULL)
518            {
519                    log_error("section_data_mark_del_article() NULL pointer error\n");
520                    return -2;
521            }
522    
523            p_article = section_data_find_article_by_aid(p_section, aid);
524          if (p_article == NULL)          if (p_article == NULL)
525          {          {
526                  return -1; // Not found                  return -1; // Not found


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

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