/[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.5 by sysadm, Wed May 21 09:18:17 2025 UTC
# Line 16  Line 16 
16    
17  #include "section_list.h"  #include "section_list.h"
18  #include "log.h"  #include "log.h"
 #include "io.h"  
19  #include "trie_dict.h"  #include "trie_dict.h"
20  #include <stdio.h>  #include <stdio.h>
21  #include <string.h>  #include <string.h>
# Line 27  Line 26 
26  #include <sys/shm.h>  #include <sys/shm.h>
27  #include <sys/ipc.h>  #include <sys/ipc.h>
28    
29  #define ARTICLE_BLOCK_PER_SHM 50 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate  // ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT should be
30  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 256  // no less than BBS_article_block_limit_per_section * BBS_max_section,
31    // in order to allocate enough memory for blocks
32    #define ARTICLE_BLOCK_PER_SHM 400 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate
33    #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 256 // limited by length (8-bit) of proj_id in ftok(path, proj_id)
34    
35  struct article_block_shm_t  struct article_block_shm_t
36  {  {
# Line 291  int section_data_free_block(SECTION_DATA Line 293  int section_data_free_block(SECTION_DATA
293          return 0;          return 0;
294  }  }
295    
296  SECTION_DATA *section_data_find_by_name(const char *sname)  SECTION_DATA *section_data_find_section_by_name(const char *sname)
297  {  {
298          int64_t index;          int64_t index;
299    
# Line 380  int section_data_append_article(SECTION_ Line 382  int section_data_append_article(SECTION_
382    
383          if (p_article->tid != 0)          if (p_article->tid != 0)
384          {          {
385                  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);
386                  if (p_topic_head == NULL)                  if (p_topic_head == NULL)
387                  {                  {
388                          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);
389                          return -4;                          return -4;
390                  }                  }
391    
392                  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);
393                  if (p_topic_tail == NULL)                  if (p_topic_tail == NULL)
394                  {                  {
395                          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 417  int section_data_append_article(SECTION_
417          return 0;          return 0;
418  }  }
419    
420  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)
421  {  {
422          ARTICLE *p_article;          ARTICLE *p_article;
423          ARTICLE_BLOCK *p_block;          ARTICLE_BLOCK *p_block;
# Line 425  ARTICLE *section_data_search_article(SEC Line 427  ARTICLE *section_data_search_article(SEC
427    
428          if (p_section == NULL)          if (p_section == NULL)
429          {          {
430                  log_error("section_data_append_article() NULL pointer error\n");                  log_error("section_data_find_article_by_aid() NULL pointer error\n");
431                  return NULL;                  return NULL;
432          }          }
433    
# Line 484  ARTICLE *section_data_search_article(SEC Line 486  ARTICLE *section_data_search_article(SEC
486          return p_article;          return p_article;
487  }  }
488    
489    ARTICLE *section_data_find_article_by_index(SECTION_DATA *p_section, int index)
490    {
491            ARTICLE *p_article;
492            ARTICLE_BLOCK *p_block;
493    
494            if (p_section == NULL)
495            {
496                    log_error("section_data_find_article_by_index() NULL pointer error\n");
497                    return NULL;
498            }
499    
500            if (index < 0 || index >= p_section->article_count)
501            {
502                    log_error("section_data_find_article_by_index(%d) is out of boundary [0, %d)\n", index, p_section->article_count);
503                    return NULL;
504            }
505    
506            p_block = p_section->p_block[index / BBS_article_limit_per_block];
507            p_article = &(p_block->articles[index % BBS_article_limit_per_block]);
508    
509            return p_article;
510    }
511    
512  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)
513  {  {
514          ARTICLE *p_article;          ARTICLE *p_article;
515    
516          p_article = section_data_search_article(p_section, aid);          if (p_section == NULL)
517            {
518                    log_error("section_data_mark_del_article() NULL pointer error\n");
519                    return -2;
520            }
521    
522            p_article = section_data_find_article_by_aid(p_section, aid);
523          if (p_article == NULL)          if (p_article == NULL)
524          {          {
525                  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