| 819 |
|
|
| 820 |
return ret; |
return ret; |
| 821 |
} |
} |
| 822 |
|
|
| 823 |
|
int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction, |
| 824 |
|
int *p_page_id, int *p_offset, int *p_article_count) |
| 825 |
|
{ |
| 826 |
|
ARTICLE *p_article = NULL; |
| 827 |
|
ARTICLE *p_next; |
| 828 |
|
int32_t aid = 0; |
| 829 |
|
int ret = 0; |
| 830 |
|
|
| 831 |
|
if (p_section == NULL || p_article_cur == NULL || p_page_id == NULL || p_offset == NULL || p_article_count == NULL) |
| 832 |
|
{ |
| 833 |
|
log_error("locate_article_in_section() NULL pointer error\n"); |
| 834 |
|
return -1; |
| 835 |
|
} |
| 836 |
|
|
| 837 |
|
// acquire lock of section |
| 838 |
|
if ((ret = section_list_rd_lock(p_section)) < 0) |
| 839 |
|
{ |
| 840 |
|
log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); |
| 841 |
|
return -2; |
| 842 |
|
} |
| 843 |
|
|
| 844 |
|
if (direction == 0) |
| 845 |
|
{ |
| 846 |
|
aid = p_article_cur->aid; |
| 847 |
|
} |
| 848 |
|
else if (direction == 1) |
| 849 |
|
{ |
| 850 |
|
aid = p_article_cur->p_topic_next->aid; |
| 851 |
|
if (aid <= p_article_cur->aid) |
| 852 |
|
{ |
| 853 |
|
aid = 0; |
| 854 |
|
} |
| 855 |
|
} |
| 856 |
|
else if (direction == -1) |
| 857 |
|
{ |
| 858 |
|
aid = p_article_cur->p_topic_prior->aid; |
| 859 |
|
if (aid >= p_article_cur->aid) |
| 860 |
|
{ |
| 861 |
|
aid = 0; |
| 862 |
|
} |
| 863 |
|
} |
| 864 |
|
|
| 865 |
|
if (aid > 0) |
| 866 |
|
{ |
| 867 |
|
p_article = section_list_find_article_with_offset(p_section, aid, p_page_id, p_offset, &p_next); |
| 868 |
|
if (p_article != NULL) |
| 869 |
|
{ |
| 870 |
|
*p_article_count = (*p_page_id == p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page); |
| 871 |
|
} |
| 872 |
|
} |
| 873 |
|
|
| 874 |
|
// release lock of section |
| 875 |
|
if (section_list_rd_unlock(p_section) < 0) |
| 876 |
|
{ |
| 877 |
|
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
| 878 |
|
ret = -2; |
| 879 |
|
} |
| 880 |
|
|
| 881 |
|
return (ret < 0 ? ret : (p_article == NULL ? 0 : 1)); |
| 882 |
|
} |