| 26 |
#include <strings.h> |
#include <strings.h> |
| 27 |
#include <unistd.h> |
#include <unistd.h> |
| 28 |
|
|
| 29 |
|
#define _POSIX_C_SOURCE 200809L |
| 30 |
|
#include <string.h> |
| 31 |
|
|
| 32 |
#define SECTION_LIST_LOAD_INTERVAL 10 // second |
#define SECTION_LIST_LOAD_INTERVAL 10 // second |
| 33 |
|
|
| 34 |
int section_list_loader_pid; |
int section_list_loader_pid; |
| 41 |
MYSQL_ROW row, row2; |
MYSQL_ROW row, row2; |
| 42 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 43 |
int32_t sid; |
int32_t sid; |
| 44 |
char master_name[BBS_username_max_len + 1]; |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
| 45 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 46 |
int ret; |
int ret; |
| 47 |
|
|
| 79 |
"SELECT username FROM section_master " |
"SELECT username FROM section_master " |
| 80 |
"INNER JOIN user_list ON section_master.UID = user_list.UID " |
"INNER JOIN user_list ON section_master.UID = user_list.UID " |
| 81 |
"WHERE SID = %d AND section_master.enable AND (NOW() BETWEEN begin_dt AND end_dt) " |
"WHERE SID = %d AND section_master.enable AND (NOW() BETWEEN begin_dt AND end_dt) " |
| 82 |
"ORDER BY major DESC LIMIT 1", |
"ORDER BY major DESC, begin_dt ASC LIMIT 3", |
| 83 |
sid); |
sid); |
| 84 |
|
|
| 85 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 94 |
ret = -3; |
ret = -3; |
| 95 |
break; |
break; |
| 96 |
} |
} |
| 97 |
if ((row2 = mysql_fetch_row(rs2))) |
|
| 98 |
{ |
master_list[0] = '\0'; |
| 99 |
strncpy(master_name, row2[0], sizeof(master_name) - 1); |
while ((row2 = mysql_fetch_row(rs2))) |
|
master_name[sizeof(master_name) - 1] = '\0'; |
|
|
} |
|
|
else |
|
| 100 |
{ |
{ |
| 101 |
master_name[0] = '\0'; |
strncat(master_list, row2[0], sizeof(master_list) - 1 - strnlen(master_list, sizeof(master_list))); |
| 102 |
|
strncat(master_list, " ", sizeof(master_list) - 1 - strnlen(master_list, sizeof(master_list))); |
| 103 |
} |
} |
| 104 |
mysql_free_result(rs2); |
mysql_free_result(rs2); |
| 105 |
|
|
| 107 |
|
|
| 108 |
if (p_section == NULL) |
if (p_section == NULL) |
| 109 |
{ |
{ |
| 110 |
p_section = section_list_create(sid, row[1], row[2], ""); |
p_section = section_list_create(sid, row[1], row[2], master_list); |
| 111 |
if (p_section == NULL) |
if (p_section == NULL) |
| 112 |
{ |
{ |
| 113 |
log_error("section_list_create() error: load new section sid = %d sname = %s\n", sid, row[1]); |
log_error("section_list_create() error: load new section sid = %d sname = %s\n", sid, row[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'; |
| 138 |
strncpy(p_section->master_name, master_name, sizeof(p_section->master_name) - 1); |
strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1); |
| 139 |
p_section->master_name[sizeof(p_section->master_name) - 1] = '\0'; |
p_section->master_list[sizeof(p_section->master_list) - 1] = '\0'; |
| 140 |
} |
} |
| 141 |
|
|
| 142 |
p_section->class_id = atoi(row[3]); |
p_section->class_id = atoi(row[3]); |
| 719 |
return -2; |
return -2; |
| 720 |
} |
} |
| 721 |
|
|
| 722 |
if (page_id >= p_section->page_count) |
if (page_id < 0 || page_id >= p_section->page_count) |
|
{ |
|
|
page_id = p_section->page_count - 1; |
|
|
} |
|
|
|
|
|
if (page_id < 0) |
|
| 723 |
{ |
{ |
| 724 |
|
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, p_section->page_count); |
| 725 |
ret = -3; |
ret = -3; |
| 726 |
} |
} |
| 727 |
else |
else |
| 741 |
} |
} |
| 742 |
p_article = p_article->p_next; |
p_article = p_article->p_next; |
| 743 |
} while (p_article != p_next_page_first_article && (*p_article_count) <= BBS_article_limit_per_page); |
} while (p_article != p_next_page_first_article && (*p_article_count) <= BBS_article_limit_per_page); |
| 744 |
|
|
| 745 |
|
if (*p_article_count != (page_id < p_section->page_count - 1 ? BBS_article_limit_per_page : p_section->last_page_visible_article_count)) |
| 746 |
|
{ |
| 747 |
|
log_error("Inconsistent visible article count %d detected in section %d page %d\n", *p_article_count, p_section->sid, page_id); |
| 748 |
|
} |
| 749 |
} |
} |
| 750 |
|
|
| 751 |
// release lock of section |
// release lock of section |
| 752 |
if ((ret = section_list_rd_unlock(p_section)) < 0) |
if (section_list_rd_unlock(p_section) < 0) |
| 753 |
{ |
{ |
| 754 |
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
| 755 |
ret = -2; |
ret = -2; |