| 698 |
|
|
| 699 |
return 0; |
return 0; |
| 700 |
} |
} |
| 701 |
|
|
| 702 |
|
int query_section_articles(SECTION_LIST *p_section, int32_t page_id, ARTICLE *p_articles[], int32_t *p_article_count) |
| 703 |
|
{ |
| 704 |
|
ARTICLE *p_article; |
| 705 |
|
ARTICLE *p_next_page_first_article; |
| 706 |
|
int ret = 0; |
| 707 |
|
|
| 708 |
|
if (p_section == NULL || p_articles == NULL || p_article_count == NULL) |
| 709 |
|
{ |
| 710 |
|
log_error("query_section_articles() NULL pointer error\n"); |
| 711 |
|
return -1; |
| 712 |
|
} |
| 713 |
|
|
| 714 |
|
// acquire lock of section |
| 715 |
|
if ((ret = section_list_rd_lock(p_section)) < 0) |
| 716 |
|
{ |
| 717 |
|
log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); |
| 718 |
|
return -2; |
| 719 |
|
} |
| 720 |
|
|
| 721 |
|
if (page_id >= p_section->page_count) |
| 722 |
|
{ |
| 723 |
|
page_id = p_section->page_count - 1; |
| 724 |
|
} |
| 725 |
|
|
| 726 |
|
if (page_id < 0) |
| 727 |
|
{ |
| 728 |
|
ret = -3; |
| 729 |
|
} |
| 730 |
|
else |
| 731 |
|
{ |
| 732 |
|
ret = page_id; |
| 733 |
|
p_article = p_section->p_page_first_article[page_id]; |
| 734 |
|
p_next_page_first_article = |
| 735 |
|
(page_id == p_section->page_count - 1 ? p_section->p_article_head : p_section->p_page_first_article[page_id + 1]); |
| 736 |
|
*p_article_count = 0; |
| 737 |
|
|
| 738 |
|
do |
| 739 |
|
{ |
| 740 |
|
if (p_article->visible) |
| 741 |
|
{ |
| 742 |
|
p_articles[*p_article_count] = p_article; |
| 743 |
|
(*p_article_count)++; |
| 744 |
|
} |
| 745 |
|
p_article = p_article->p_next; |
| 746 |
|
} while (p_article != p_next_page_first_article && (*p_article_count) <= BBS_article_limit_per_page); |
| 747 |
|
} |
| 748 |
|
|
| 749 |
|
// release lock of section |
| 750 |
|
if ((ret = section_list_rd_unlock(p_section)) < 0) |
| 751 |
|
{ |
| 752 |
|
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
| 753 |
|
ret = -2; |
| 754 |
|
} |
| 755 |
|
|
| 756 |
|
return ret; |
| 757 |
|
} |