| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#include "section_list_loader.h" |
|
| 17 |
#include "article_cache.h" |
#include "article_cache.h" |
| 18 |
#include "bbs.h" |
#include "bbs.h" |
|
#include "log.h" |
|
| 19 |
#include "database.h" |
#include "database.h" |
| 20 |
|
#include "log.h" |
| 21 |
#include "menu.h" |
#include "menu.h" |
| 22 |
#include <stdio.h> |
#include "section_list_loader.h" |
|
#include <string.h> |
|
| 23 |
#include <errno.h> |
#include <errno.h> |
| 24 |
#include <signal.h> |
#include <signal.h> |
| 25 |
|
#include <stdio.h> |
| 26 |
#include <stdlib.h> |
#include <stdlib.h> |
| 27 |
#include <string.h> |
#include <string.h> |
|
#include <strings.h> |
|
| 28 |
#include <unistd.h> |
#include <unistd.h> |
| 29 |
|
|
| 30 |
int section_list_loader_pid; |
int section_list_loader_pid; |
| 131 |
break; |
break; |
| 132 |
} |
} |
| 133 |
|
|
| 134 |
strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1); |
strncpy(p_section->sname, row[0], sizeof(p_section->sname) - 1); |
| 135 |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 136 |
strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1); |
strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1); |
| 137 |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
| 153 |
} |
} |
| 154 |
|
|
| 155 |
cleanup: |
cleanup: |
| 156 |
|
mysql_free_result(rs2); |
| 157 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 158 |
mysql_close(db); |
mysql_close(db); |
| 159 |
|
|
| 321 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 322 |
mysql_close(db); |
mysql_close(db); |
| 323 |
|
|
| 324 |
|
article_cache_cleanup(); |
| 325 |
|
|
| 326 |
return (ret < 0 ? ret : article_count); |
return (ret < 0 ? ret : article_count); |
| 327 |
} |
} |
| 328 |
|
|
| 589 |
p_article->excerption = 0; |
p_article->excerption = 0; |
| 590 |
break; |
break; |
| 591 |
case 'F': // Set article on top |
case 'F': // Set article on top |
|
p_article->ontop = 1; |
|
|
break; |
|
| 592 |
case 'V': // Unset article on top |
case 'V': // Unset article on top |
| 593 |
p_article->ontop = 0; |
p_article->ontop = (row[2][0] == 'F' ? 1 : 0); |
| 594 |
|
if (section_list_update_article_ontop(p_section, p_article) < 0) |
| 595 |
|
{ |
| 596 |
|
log_error("section_list_update_article_ontop(sid=%d, aid=%d) error\n", |
| 597 |
|
p_section->sid, p_article->aid); |
| 598 |
|
} |
| 599 |
break; |
break; |
| 600 |
case 'Z': // Set article as trnasship |
case 'Z': // Set article as trnasship |
| 601 |
p_article->transship = 1; |
p_article->transship = 1; |
| 753 |
|
|
| 754 |
// Child process exit |
// Child process exit |
| 755 |
|
|
| 756 |
|
article_cache_cleanup(); |
| 757 |
|
|
| 758 |
// Detach data pools shm |
// Detach data pools shm |
| 759 |
detach_section_list_shm(); |
detach_section_list_shm(); |
| 760 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 787 |
return 0; |
return 0; |
| 788 |
} |
} |
| 789 |
|
|
| 790 |
int query_section_articles(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], int *p_article_count, int *p_page_count) |
int query_section_articles(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], |
| 791 |
|
int *p_article_count, int *p_page_count, int *p_ontop_start_offset) |
| 792 |
{ |
{ |
| 793 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 794 |
ARTICLE *p_next_page_first_article; |
ARTICLE *p_next_page_first_article; |
| 795 |
int ret = 0; |
int ret = 0; |
| 796 |
|
int i; |
| 797 |
|
|
| 798 |
if (p_section == NULL || p_articles == NULL || p_article_count == NULL || p_page_count == NULL) |
if (p_section == NULL || p_articles == NULL || p_article_count == NULL || p_page_count == NULL || p_ontop_start_offset == NULL) |
| 799 |
{ |
{ |
| 800 |
log_error("query_section_articles() NULL pointer error\n"); |
log_error("query_section_articles() NULL pointer error\n"); |
| 801 |
return -1; |
return -1; |
| 808 |
return -2; |
return -2; |
| 809 |
} |
} |
| 810 |
|
|
| 811 |
*p_page_count = p_section->page_count; |
*p_page_count = section_list_page_count_with_ontop(p_section); |
| 812 |
|
*p_article_count = 0; |
| 813 |
|
*p_ontop_start_offset = BBS_article_limit_per_page; |
| 814 |
|
|
| 815 |
if (p_section->visible_article_count == 0) |
if (p_section->visible_article_count == 0) |
| 816 |
{ |
{ |
| 817 |
*p_article_count = 0; |
// empty section |
| 818 |
} |
} |
| 819 |
else if (page_id < 0 || page_id >= p_section->page_count) |
else if (page_id < 0 || page_id >= *p_page_count) |
| 820 |
{ |
{ |
| 821 |
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, p_section->page_count); |
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, *p_page_count); |
| 822 |
ret = -3; |
ret = -3; |
| 823 |
} |
} |
| 824 |
else |
else |
| 825 |
{ |
{ |
| 826 |
ret = page_id; |
ret = page_id; |
|
p_article = p_section->p_page_first_article[page_id]; |
|
|
p_next_page_first_article = |
|
|
(page_id == p_section->page_count - 1 ? p_section->p_article_head : p_section->p_page_first_article[page_id + 1]); |
|
|
*p_article_count = 0; |
|
| 827 |
|
|
| 828 |
do |
if (page_id <= p_section->page_count - 1) |
| 829 |
{ |
{ |
| 830 |
if (p_article->visible) |
p_article = p_section->p_page_first_article[page_id]; |
| 831 |
|
p_next_page_first_article = |
| 832 |
|
(page_id == p_section->page_count - 1 ? p_section->p_article_head : p_section->p_page_first_article[page_id + 1]); |
| 833 |
|
|
| 834 |
|
do |
| 835 |
|
{ |
| 836 |
|
if (p_article->visible) |
| 837 |
|
{ |
| 838 |
|
p_articles[*p_article_count] = p_article; |
| 839 |
|
(*p_article_count)++; |
| 840 |
|
} |
| 841 |
|
p_article = p_article->p_next; |
| 842 |
|
} while (p_article != p_next_page_first_article && (*p_article_count) <= BBS_article_limit_per_page); |
| 843 |
|
|
| 844 |
|
if (*p_article_count != (page_id < p_section->page_count - 1 ? BBS_article_limit_per_page : p_section->last_page_visible_article_count)) |
| 845 |
{ |
{ |
| 846 |
p_articles[*p_article_count] = p_article; |
log_error("Inconsistent visible article count %d detected in section %d page %d\n", *p_article_count, p_section->sid, page_id); |
|
(*p_article_count)++; |
|
| 847 |
} |
} |
| 848 |
p_article = p_article->p_next; |
} |
| 849 |
} while (p_article != p_next_page_first_article && (*p_article_count) <= BBS_article_limit_per_page); |
|
| 850 |
|
*p_ontop_start_offset = *p_article_count; |
| 851 |
|
|
| 852 |
if (*p_article_count != (page_id < p_section->page_count - 1 ? BBS_article_limit_per_page : p_section->last_page_visible_article_count)) |
// Append ontop articles |
| 853 |
|
if (page_id >= p_section->page_count - 1) |
| 854 |
{ |
{ |
| 855 |
log_error("Inconsistent visible article count %d detected in section %d page %d\n", *p_article_count, p_section->sid, page_id); |
i = (page_id == p_section->page_count - 1 |
| 856 |
|
? 0 |
| 857 |
|
: (page_id - p_section->page_count + 1) * BBS_article_limit_per_page - p_section->last_page_visible_article_count); |
| 858 |
|
while (*p_article_count < BBS_article_limit_per_page && i < p_section->ontop_article_count) |
| 859 |
|
{ |
| 860 |
|
p_articles[(*p_article_count)++] = p_section->p_ontop_articles[i++]; |
| 861 |
|
} |
| 862 |
} |
} |
| 863 |
} |
} |
| 864 |
|
|
| 955 |
} |
} |
| 956 |
p_article = p_article->p_next; |
p_article = p_article->p_next; |
| 957 |
} |
} |
| 958 |
|
|
| 959 |
|
// Include ontop articles |
| 960 |
|
*p_article_count = section_list_page_article_count_with_ontop(p_section, page_id); |
| 961 |
} |
} |
| 962 |
} |
} |
| 963 |
|
|