| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
section_list_display.c - description |
/* |
| 3 |
------------------- |
* section_list_display |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - user interactive feature of section articles list |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "article_cache.h" |
#include "article_cache.h" |
| 14 |
#include "article_favor.h" |
#include "article_favor.h" |
| 35 |
#include <time.h> |
#include <time.h> |
| 36 |
#include <sys/param.h> |
#include <sys/param.h> |
| 37 |
|
|
| 38 |
#define TITLE_SEARCH_MAX_LEN 60 |
enum _section_list_display_constant_t |
| 39 |
|
{ |
| 40 |
|
TITLE_SEARCH_MAX_LEN = 60, |
| 41 |
|
}; |
| 42 |
|
|
| 43 |
static int32_t section_aid_locations[BBS_max_section] = {0}; |
static int32_t section_aid_locations[BBS_max_section] = {0}; |
| 44 |
static int section_topic_view_mode = 0; |
static int section_topic_view_mode = 0; |
| 58 |
QUERY_USER, |
QUERY_USER, |
| 59 |
SET_FAVOR_ARTICLE, |
SET_FAVOR_ARTICLE, |
| 60 |
UNSET_FAVOR_ARTICLE, |
UNSET_FAVOR_ARTICLE, |
| 61 |
|
SET_EXCERPTION_ARTICLE, |
| 62 |
FIRST_TOPIC_ARTICLE, |
FIRST_TOPIC_ARTICLE, |
| 63 |
LAST_TOPIC_ARTICLE, |
LAST_TOPIC_ARTICLE, |
| 64 |
LAST_SECTION_ARTICLE, |
LAST_SECTION_ARTICLE, |
| 72 |
SEARCH_USER, |
SEARCH_USER, |
| 73 |
}; |
}; |
| 74 |
|
|
| 75 |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset) |
static int section_list_draw_items(int page_id, const ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset) |
| 76 |
{ |
{ |
| 77 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
| 78 |
struct tm tm_sub; |
struct tm tm_sub; |
| 102 |
is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); |
is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); |
| 103 |
if (is_viewed < 0) |
if (is_viewed < 0) |
| 104 |
{ |
{ |
| 105 |
log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid); |
log_error("article_view_log_is_viewed(aid=%d) error", p_articles[i]->aid); |
| 106 |
is_viewed = 0; |
is_viewed = 0; |
| 107 |
} |
} |
| 108 |
} |
} |
| 112 |
is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor); |
is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor); |
| 113 |
if (is_favor < 0) |
if (is_favor < 0) |
| 114 |
{ |
{ |
| 115 |
log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid); |
log_error("article_favor_check(aid=%d) error", p_articles[i]->aid); |
| 116 |
is_favor = 0; |
is_favor = 0; |
| 117 |
} |
} |
| 118 |
} |
} |
| 226 |
|
|
| 227 |
if (master_list[0] != '\0') |
if (master_list[0] != '\0') |
| 228 |
{ |
{ |
| 229 |
snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list); |
snprintf(str_section_master, sizeof(str_section_master), "版主: %s", master_list); |
| 230 |
} |
} |
| 231 |
snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname); |
snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname); |
| 232 |
|
|
| 271 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 272 |
{ |
{ |
| 273 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 274 |
|
|
| 275 |
|
// Refresh current action |
| 276 |
|
if (user_online_update(NULL) < 0) |
| 277 |
|
{ |
| 278 |
|
log_error("user_online_update(NULL) error"); |
| 279 |
|
} |
| 280 |
} |
} |
| 281 |
|
|
| 282 |
switch (ch) |
switch (ch) |
| 283 |
{ |
{ |
| 284 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 285 |
log_error("KEY_NULL\n"); |
log_debug("KEY_NULL"); |
| 286 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 287 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 288 |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |
| 289 |
{ |
{ |
| 290 |
log_error("User input timeout\n"); |
log_debug("User input timeout"); |
| 291 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 292 |
} |
} |
| 293 |
continue; |
continue; |
| 342 |
return UNSET_FAVOR_ARTICLE; |
return UNSET_FAVOR_ARTICLE; |
| 343 |
} |
} |
| 344 |
break; |
break; |
| 345 |
|
case 'm': |
| 346 |
|
if (item_count > 0) |
| 347 |
|
{ |
| 348 |
|
return SET_EXCERPTION_ARTICLE; |
| 349 |
|
} |
| 350 |
|
break; |
| 351 |
case KEY_HOME: |
case KEY_HOME: |
| 352 |
*p_page_id = 0; |
*p_page_id = 0; |
| 353 |
case 'P': |
case 'P': |
| 597 |
char stitle[BBS_section_title_max_len + 1]; |
char stitle[BBS_section_title_max_len + 1]; |
| 598 |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
| 599 |
char page_info_str[LINE_BUFFER_LEN]; |
char page_info_str[LINE_BUFFER_LEN]; |
| 600 |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
const ARTICLE *p_articles[BBS_article_limit_per_page]; |
| 601 |
int article_count; |
int article_count; |
| 602 |
int page_count; |
int page_count; |
| 603 |
int ontop_start_offset; |
int ontop_start_offset; |
| 622 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 623 |
if (p_section == NULL) |
if (p_section == NULL) |
| 624 |
{ |
{ |
| 625 |
log_error("Section %s not found\n", sname); |
log_error("Section %s not found", sname); |
| 626 |
return -1; |
return -1; |
| 627 |
} |
} |
| 628 |
|
|
| 629 |
if (!checkpriv(&BBS_priv, p_section->sid, S_LIST)) |
if (!checkpriv(&BBS_priv, p_section->sid, S_LIST)) |
| 630 |
{ |
{ |
| 631 |
log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n", |
log_error("Forbid access to unauthorized section, sid=%d, uid=%d", |
| 632 |
p_section->sid, BBS_priv.uid); |
p_section->sid, BBS_priv.uid); |
| 633 |
return -1; |
return -1; |
| 634 |
} |
} |
| 637 |
|
|
| 638 |
if (get_section_info(p_section, NULL, stitle, master_list) < 0) |
if (get_section_info(p_section, NULL, stitle, master_list) < 0) |
| 639 |
{ |
{ |
| 640 |
log_error("get_section_info(sid=%d) error\n", p_section->sid); |
log_error("get_section_info(sid=%d) error", p_section->sid); |
| 641 |
return -4; |
return -4; |
| 642 |
} |
} |
| 643 |
|
|
| 656 |
p_article_locate = article_block_find_by_aid(aid_location); |
p_article_locate = article_block_find_by_aid(aid_location); |
| 657 |
if (p_article_locate == NULL) |
if (p_article_locate == NULL) |
| 658 |
{ |
{ |
| 659 |
log_error("article_block_find_by_aid(%d) error\n", aid_location); |
log_error("article_block_find_by_aid(%d) error", aid_location); |
| 660 |
return -3; |
return -3; |
| 661 |
} |
} |
| 662 |
|
|
| 664 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 665 |
if (ret < 0) |
if (ret < 0) |
| 666 |
{ |
{ |
| 667 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", |
| 668 |
p_section->sid, p_article_locate->aid); |
p_section->sid, p_article_locate->aid); |
| 669 |
return -3; |
return -3; |
| 670 |
} |
} |
| 672 |
|
|
| 673 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 674 |
{ |
{ |
| 675 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 676 |
return -2; |
return -2; |
| 677 |
} |
} |
| 678 |
|
|
| 679 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 680 |
if (ret < 0) |
if (ret < 0) |
| 681 |
{ |
{ |
| 682 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 683 |
return -3; |
return -3; |
| 684 |
} |
} |
| 685 |
|
|
| 703 |
ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset); |
ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset); |
| 704 |
if (ret < 0) |
if (ret < 0) |
| 705 |
{ |
{ |
| 706 |
log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("section_list_draw_items(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 707 |
return -4; |
return -4; |
| 708 |
} |
} |
| 709 |
|
|
| 716 |
|
|
| 717 |
if (user_online_update(sname) < 0) |
if (user_online_update(sname) < 0) |
| 718 |
{ |
{ |
| 719 |
log_error("user_online_update(%s) error\n", sname); |
log_error("user_online_update(%s) error", sname); |
| 720 |
} |
} |
| 721 |
|
|
| 722 |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
| 725 |
{ |
{ |
| 726 |
case EXIT_SECTION: |
case EXIT_SECTION: |
| 727 |
// Update current aid location |
// Update current aid location |
| 728 |
if (p_articles[selected_index] != NULL) |
if (selected_index < article_count && p_articles[selected_index] != NULL) |
| 729 |
{ |
{ |
| 730 |
if (selected_index >= ontop_start_offset) |
if (selected_index >= ontop_start_offset) |
| 731 |
{ |
{ |
| 732 |
ret = last_article_in_section(p_section, &p_article_locate); |
ret = last_article_in_section(p_section, &p_article_locate); |
| 733 |
if (ret < 0) |
if (ret < 0) |
| 734 |
{ |
{ |
| 735 |
log_error("last_article_in_section(sid=%d) error\n", p_section->sid); |
log_error("last_article_in_section(sid=%d) error", p_section->sid); |
| 736 |
return -3; |
return -3; |
| 737 |
} |
} |
| 738 |
else if (ret == 0) |
else if (ret == 0) |
| 754 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 755 |
if (ret < 0) |
if (ret < 0) |
| 756 |
{ |
{ |
| 757 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 758 |
return -3; |
return -3; |
| 759 |
} |
} |
| 760 |
if (article_count == 0) // empty section |
if (article_count == 0) // empty section |
| 773 |
|
|
| 774 |
if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0) |
if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0) |
| 775 |
{ |
{ |
| 776 |
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
log_error("article_cache_load(aid=%d, cid=%d) error", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 777 |
break; |
break; |
| 778 |
} |
} |
| 779 |
|
|
| 780 |
if (user_online_update("VIEW_ARTICLE") < 0) |
if (user_online_update("VIEW_ARTICLE") < 0) |
| 781 |
{ |
{ |
| 782 |
log_error("user_online_update(VIEW_ARTICLE) error\n"); |
log_error("user_online_update(VIEW_ARTICLE) error"); |
| 783 |
} |
} |
| 784 |
|
|
| 785 |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
| 787 |
|
|
| 788 |
if (article_cache_unload(&cache) < 0) |
if (article_cache_unload(&cache) < 0) |
| 789 |
{ |
{ |
| 790 |
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
log_error("article_cache_unload(aid=%d, cid=%d) error", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 791 |
break; |
break; |
| 792 |
} |
} |
| 793 |
|
|
| 794 |
// Update article_view_log |
// Update article_view_log |
| 795 |
if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0) |
if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0) |
| 796 |
{ |
{ |
| 797 |
log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_view_log_set_viewed(aid=%d) error", p_articles[selected_index]->aid); |
| 798 |
} |
} |
| 799 |
|
|
| 800 |
switch (ret) |
switch (ret) |
| 810 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 811 |
if (ret < 0) |
if (ret < 0) |
| 812 |
{ |
{ |
| 813 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 814 |
return -3; |
return -3; |
| 815 |
} |
} |
| 816 |
|
|
| 841 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 842 |
if (ret < 0) |
if (ret < 0) |
| 843 |
{ |
{ |
| 844 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 845 |
return -3; |
return -3; |
| 846 |
} |
} |
| 847 |
|
|
| 868 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 869 |
if (ret < 0) |
if (ret < 0) |
| 870 |
{ |
{ |
| 871 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error", |
| 872 |
p_section->sid, p_articles[selected_index]->aid, direction); |
p_section->sid, p_articles[selected_index]->aid, direction); |
| 873 |
return -3; |
return -3; |
| 874 |
} |
} |
| 877 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 878 |
if (ret < 0) |
if (ret < 0) |
| 879 |
{ |
{ |
| 880 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 881 |
return -3; |
return -3; |
| 882 |
} |
} |
| 883 |
loop = 1; |
loop = 1; |
| 886 |
case 'r': // Reply article |
case 'r': // Reply article |
| 887 |
if (user_online_update("REPLY_ARTICLE") < 0) |
if (user_online_update("REPLY_ARTICLE") < 0) |
| 888 |
{ |
{ |
| 889 |
log_error("user_online_update(REPLY_ARTICLE) error\n"); |
log_error("user_online_update(REPLY_ARTICLE) error"); |
| 890 |
} |
} |
| 891 |
|
|
| 892 |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 893 |
{ |
{ |
| 894 |
log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_reply(aid=%d) error", p_articles[selected_index]->aid); |
| 895 |
} |
} |
| 896 |
else if (ret > 0) // Article replied |
else if (ret > 0) // Article replied |
| 897 |
{ |
{ |
| 898 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 899 |
if (ret < 0) |
if (ret < 0) |
| 900 |
{ |
{ |
| 901 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 902 |
return -3; |
return -3; |
| 903 |
} |
} |
| 904 |
} |
} |
| 912 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 913 |
if (ret < 0) |
if (ret < 0) |
| 914 |
{ |
{ |
| 915 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error", |
| 916 |
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 917 |
return -3; |
return -3; |
| 918 |
} |
} |
| 923 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 924 |
if (ret < 0) |
if (ret < 0) |
| 925 |
{ |
{ |
| 926 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 927 |
return -3; |
return -3; |
| 928 |
} |
} |
| 929 |
} |
} |
| 938 |
|
|
| 939 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 940 |
{ |
{ |
| 941 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 942 |
return -2; |
return -2; |
| 943 |
} |
} |
| 944 |
break; |
break; |
| 946 |
display_nickname = !display_nickname; |
display_nickname = !display_nickname; |
| 947 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 948 |
{ |
{ |
| 949 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 950 |
return -2; |
return -2; |
| 951 |
} |
} |
| 952 |
break; |
break; |
| 953 |
case POST_ARTICLE: |
case POST_ARTICLE: |
| 954 |
if (user_online_update("POST_ARTICLE") < 0) |
if (user_online_update("POST_ARTICLE") < 0) |
| 955 |
{ |
{ |
| 956 |
log_error("user_online_update(POST_ARTICLE) error\n"); |
log_error("user_online_update(POST_ARTICLE) error"); |
| 957 |
} |
} |
| 958 |
|
|
| 959 |
if ((ret = article_post(p_section, &article_new)) < 0) |
if ((ret = article_post(p_section, &article_new)) < 0) |
| 960 |
{ |
{ |
| 961 |
log_error("article_post(sid=%d) error\n", p_section->sid); |
log_error("article_post(sid=%d) error", p_section->sid); |
| 962 |
} |
} |
| 963 |
else if (ret > 0) // New article posted |
else if (ret > 0) // New article posted |
| 964 |
{ |
{ |
| 965 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 966 |
if (ret < 0) |
if (ret < 0) |
| 967 |
{ |
{ |
| 968 |
log_error("query_section_articles(sid=%d, page_id=%d) error: %d\n", p_section->sid, page_id, ret); |
log_error("query_section_articles(sid=%d, page_id=%d) error: %d", p_section->sid, page_id, ret); |
| 969 |
return -3; |
return -3; |
| 970 |
} |
} |
| 971 |
} |
} |
| 972 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 973 |
{ |
{ |
| 974 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 975 |
return -2; |
return -2; |
| 976 |
} |
} |
| 977 |
break; |
break; |
| 984 |
|
|
| 985 |
if (user_online_update("EDIT_ARTICLE") < 0) |
if (user_online_update("EDIT_ARTICLE") < 0) |
| 986 |
{ |
{ |
| 987 |
log_error("user_online_update() error\n"); |
log_error("user_online_update() error"); |
| 988 |
} |
} |
| 989 |
|
|
| 990 |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 991 |
{ |
{ |
| 992 |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_modify(aid=%d) error", p_articles[selected_index]->aid); |
| 993 |
} |
} |
| 994 |
else if (ret > 0) // Article modified |
else if (ret > 0) // Article modified |
| 995 |
{ |
{ |
| 996 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 997 |
if (ret < 0) |
if (ret < 0) |
| 998 |
{ |
{ |
| 999 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 1000 |
return -3; |
return -3; |
| 1001 |
} |
} |
| 1002 |
} |
} |
| 1003 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1004 |
{ |
{ |
| 1005 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1006 |
return -2; |
return -2; |
| 1007 |
} |
} |
| 1008 |
break; |
break; |
| 1014 |
} |
} |
| 1015 |
if ((ret = article_del(p_section, p_articles[selected_index])) < 0) |
if ((ret = article_del(p_section, p_articles[selected_index])) < 0) |
| 1016 |
{ |
{ |
| 1017 |
log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_del(aid=%d) error", p_articles[selected_index]->aid); |
| 1018 |
} |
} |
| 1019 |
else if (ret > 0) // Article deleted |
else if (ret > 0) // Article deleted |
| 1020 |
{ |
{ |
| 1040 |
} |
} |
| 1041 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1042 |
{ |
{ |
| 1043 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1044 |
return -2; |
return -2; |
| 1045 |
} |
} |
| 1046 |
break; |
break; |
| 1047 |
case QUERY_ARTICLE: |
case QUERY_ARTICLE: |
| 1048 |
if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0) |
if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0) |
| 1049 |
{ |
{ |
| 1050 |
log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("display_article_meta(aid=%d) error", p_articles[selected_index]->aid); |
| 1051 |
} |
} |
| 1052 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1053 |
{ |
{ |
| 1054 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1055 |
return -2; |
return -2; |
| 1056 |
} |
} |
| 1057 |
break; |
break; |
| 1058 |
case QUERY_USER: |
case QUERY_USER: |
| 1059 |
if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0) |
if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0) |
| 1060 |
{ |
{ |
| 1061 |
log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid); |
log_error("query_user_info_by_uid(uid=%d) error", p_articles[selected_index]->uid); |
| 1062 |
return -2; |
return -2; |
| 1063 |
} |
} |
| 1064 |
else if (ret == 0) |
else if (ret == 0) |
| 1069 |
} |
} |
| 1070 |
else if (user_info_display(&user_info) < 0) // && ret > 0 |
else if (user_info_display(&user_info) < 0) // && ret > 0 |
| 1071 |
{ |
{ |
| 1072 |
log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid); |
log_error("user_info_display(uid=%d) error", p_articles[selected_index]->uid); |
| 1073 |
} |
} |
| 1074 |
|
|
| 1075 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1076 |
{ |
{ |
| 1077 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1078 |
return -2; |
return -2; |
| 1079 |
} |
} |
| 1080 |
break; |
break; |
| 1085 |
&BBS_article_favor, 1); |
&BBS_article_favor, 1); |
| 1086 |
if (ret < 0) |
if (ret < 0) |
| 1087 |
{ |
{ |
| 1088 |
log_error("article_favor_set(aid=%d, 1) error\n", |
log_error("article_favor_set(aid=%d, 1) error", |
| 1089 |
p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
| 1090 |
} |
} |
| 1091 |
break; |
break; |
| 1096 |
&BBS_article_favor, 0); |
&BBS_article_favor, 0); |
| 1097 |
if (ret < 0) |
if (ret < 0) |
| 1098 |
{ |
{ |
| 1099 |
log_error("article_favor_set(aid=%d, 0) error\n", |
log_error("article_favor_set(aid=%d, 0) error", |
| 1100 |
p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
| 1101 |
} |
} |
| 1102 |
break; |
break; |
| 1103 |
|
case SET_EXCERPTION_ARTICLE: |
| 1104 |
|
if (checkpriv(&BBS_priv, p_section->sid, S_POST | S_MAN_S)) |
| 1105 |
|
{ |
| 1106 |
|
ret = article_excerption_set(p_section, p_articles[selected_index]->aid, (p_articles[selected_index]->excerption ? 0 : 1)); |
| 1107 |
|
if (ret < 0) |
| 1108 |
|
{ |
| 1109 |
|
log_error("article_excerption_set(sid=%d, aid=%d, set=%d) error\n", |
| 1110 |
|
p_section->sid, p_articles[selected_index]->aid, (p_articles[selected_index]->excerption ? 0 : 1)); |
| 1111 |
|
} |
| 1112 |
|
} |
| 1113 |
|
break; |
| 1114 |
case FIRST_TOPIC_ARTICLE: |
case FIRST_TOPIC_ARTICLE: |
| 1115 |
case LAST_TOPIC_ARTICLE: |
case LAST_TOPIC_ARTICLE: |
| 1116 |
page_id_cur = page_id; |
page_id_cur = page_id; |
| 1119 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 1120 |
if (ret < 0) |
if (ret < 0) |
| 1121 |
{ |
{ |
| 1122 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error", |
| 1123 |
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 1124 |
return -3; |
return -3; |
| 1125 |
} |
} |
| 1128 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1129 |
if (ret < 0) |
if (ret < 0) |
| 1130 |
{ |
{ |
| 1131 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 1132 |
return -3; |
return -3; |
| 1133 |
} |
} |
| 1134 |
} |
} |
| 1138 |
ret = last_article_in_section(p_section, &p_article_locate); |
ret = last_article_in_section(p_section, &p_article_locate); |
| 1139 |
if (ret < 0) |
if (ret < 0) |
| 1140 |
{ |
{ |
| 1141 |
log_error("last_article_in_section(sid=%d) error\n", p_section->sid); |
log_error("last_article_in_section(sid=%d) error", p_section->sid); |
| 1142 |
return -3; |
return -3; |
| 1143 |
} |
} |
| 1144 |
else if (ret == 0) |
else if (ret == 0) |
| 1149 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 1150 |
if (ret < 0) |
if (ret < 0) |
| 1151 |
{ |
{ |
| 1152 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", |
| 1153 |
p_section->sid, p_article_locate->aid); |
p_section->sid, p_article_locate->aid); |
| 1154 |
return -3; |
return -3; |
| 1155 |
} |
} |
| 1158 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1159 |
if (ret < 0) |
if (ret < 0) |
| 1160 |
{ |
{ |
| 1161 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 1162 |
return -3; |
return -3; |
| 1163 |
} |
} |
| 1164 |
} |
} |
| 1167 |
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); |
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); |
| 1168 |
if (ret < 0) |
if (ret < 0) |
| 1169 |
{ |
{ |
| 1170 |
log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n", |
log_error("scan_unread_article_in_section(sid=%d, aid=%d) error", |
| 1171 |
p_section->sid, p_articles[selected_index]->aid); |
p_section->sid, p_articles[selected_index]->aid); |
| 1172 |
return -3; |
return -3; |
| 1173 |
} |
} |
| 1180 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 1181 |
if (ret < 0) |
if (ret < 0) |
| 1182 |
{ |
{ |
| 1183 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", |
| 1184 |
p_section->sid, p_article_locate->aid); |
p_section->sid, p_article_locate->aid); |
| 1185 |
return -3; |
return -3; |
| 1186 |
} |
} |
| 1189 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1190 |
if (ret < 0) |
if (ret < 0) |
| 1191 |
{ |
{ |
| 1192 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 1193 |
return -3; |
return -3; |
| 1194 |
} |
} |
| 1195 |
} |
} |
| 1204 |
moveto(SCREEN_ROWS, 1); |
moveto(SCREEN_ROWS, 1); |
| 1205 |
clrtoeol(); |
clrtoeol(); |
| 1206 |
get_data(SCREEN_ROWS, 1, |
get_data(SCREEN_ROWS, 1, |
| 1207 |
(direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "), |
(direction == 1 ? "↓搜寻作者: " : "↑搜寻作者: "), |
| 1208 |
username, sizeof(username), BBS_username_max_len); |
username, sizeof(username), BBS_username_max_len); |
| 1209 |
|
|
| 1210 |
if (username[0] == '\0') |
if (username[0] == '\0') |
| 1215 |
// Verify format |
// Verify format |
| 1216 |
for (i = 0, ok = 1; ok && username[i] != '\0'; i++) |
for (i = 0, ok = 1; ok && username[i] != '\0'; i++) |
| 1217 |
{ |
{ |
| 1218 |
if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_')))) |
if (!(isalpha((int)username[i]) || (i > 0 && (isdigit((int)username[i]) || username[i] == '_')))) |
| 1219 |
{ |
{ |
| 1220 |
ok = 0; |
ok = 0; |
| 1221 |
} |
} |
| 1232 |
ret = query_user_info_by_username(username, 1, &uid, username_list); |
ret = query_user_info_by_username(username, 1, &uid, username_list); |
| 1233 |
if (ret < 0) |
if (ret < 0) |
| 1234 |
{ |
{ |
| 1235 |
log_error("query_user_info_by_username(%s) error\n", username); |
log_error("query_user_info_by_username(%s) error", username); |
| 1236 |
break; |
break; |
| 1237 |
} |
} |
| 1238 |
|
|
| 1242 |
direction, uid, &p_article_locate); |
direction, uid, &p_article_locate); |
| 1243 |
if (ret < 0) |
if (ret < 0) |
| 1244 |
{ |
{ |
| 1245 |
log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n", |
log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error", |
| 1246 |
p_section->sid, p_articles[selected_index]->aid, direction, uid); |
p_section->sid, p_articles[selected_index]->aid, direction, uid); |
| 1247 |
return -3; |
return -3; |
| 1248 |
} |
} |
| 1257 |
direction, username, &p_article_locate); |
direction, username, &p_article_locate); |
| 1258 |
if (ret < 0) |
if (ret < 0) |
| 1259 |
{ |
{ |
| 1260 |
log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n", |
log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error", |
| 1261 |
p_section->sid, p_articles[selected_index]->aid, direction, username); |
p_section->sid, p_articles[selected_index]->aid, direction, username); |
| 1262 |
return -3; |
return -3; |
| 1263 |
} |
} |
| 1272 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 1273 |
if (ret < 0) |
if (ret < 0) |
| 1274 |
{ |
{ |
| 1275 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", |
| 1276 |
p_section->sid, p_article_locate->aid); |
p_section->sid, p_article_locate->aid); |
| 1277 |
return -3; |
return -3; |
| 1278 |
} |
} |
| 1281 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1282 |
if (ret < 0) |
if (ret < 0) |
| 1283 |
{ |
{ |
| 1284 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 1285 |
return -3; |
return -3; |
| 1286 |
} |
} |
| 1287 |
} |
} |
| 1293 |
moveto(SCREEN_ROWS, 1); |
moveto(SCREEN_ROWS, 1); |
| 1294 |
clrtoeol(); |
clrtoeol(); |
| 1295 |
get_data(SCREEN_ROWS, 1, |
get_data(SCREEN_ROWS, 1, |
| 1296 |
(direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "), |
(direction == 1 ? "↓搜寻标题: " : "↑搜寻标题: "), |
| 1297 |
title, sizeof(title), TITLE_SEARCH_MAX_LEN); |
title, sizeof(title), TITLE_SEARCH_MAX_LEN); |
| 1298 |
|
|
| 1299 |
if (title[0] == '\0') |
if (title[0] == '\0') |
| 1305 |
direction, title, &p_article_locate); |
direction, title, &p_article_locate); |
| 1306 |
if (ret < 0) |
if (ret < 0) |
| 1307 |
{ |
{ |
| 1308 |
log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n", |
log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error", |
| 1309 |
p_section->sid, p_articles[selected_index]->aid, direction, title); |
p_section->sid, p_articles[selected_index]->aid, direction, title); |
| 1310 |
return -3; |
return -3; |
| 1311 |
} |
} |
| 1319 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 1320 |
if (ret < 0) |
if (ret < 0) |
| 1321 |
{ |
{ |
| 1322 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", |
| 1323 |
p_section->sid, p_article_locate->aid); |
p_section->sid, p_article_locate->aid); |
| 1324 |
return -3; |
return -3; |
| 1325 |
} |
} |
| 1328 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1329 |
if (ret < 0) |
if (ret < 0) |
| 1330 |
{ |
{ |
| 1331 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); |
| 1332 |
return -3; |
return -3; |
| 1333 |
} |
} |
| 1334 |
} |
} |
| 1337 |
user_list_search(); |
user_list_search(); |
| 1338 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1339 |
{ |
{ |
| 1340 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1341 |
return -2; |
return -2; |
| 1342 |
} |
} |
| 1343 |
break; |
break; |
| 1346 |
display_file(DATA_READ_HELP, 1); |
display_file(DATA_READ_HELP, 1); |
| 1347 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1348 |
{ |
{ |
| 1349 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1350 |
return -2; |
return -2; |
| 1351 |
} |
} |
| 1352 |
break; |
break; |
| 1353 |
case VIEW_EX_DIR: |
case VIEW_EX_DIR: |
| 1354 |
if (section_list_ex_dir_display(p_section) < 0) |
if (section_list_ex_dir_display(p_section) < 0) |
| 1355 |
{ |
{ |
| 1356 |
log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid); |
log_error("section_list_ex_dir_display(sid=%d) error", p_section->sid); |
| 1357 |
} |
} |
| 1358 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1359 |
{ |
{ |
| 1360 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1361 |
return -2; |
return -2; |
| 1362 |
} |
} |
| 1363 |
break; |
break; |
| 1365 |
show_top10_menu(NULL); |
show_top10_menu(NULL); |
| 1366 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1367 |
{ |
{ |
| 1368 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error"); |
| 1369 |
return -2; |
return -2; |
| 1370 |
} |
} |
| 1371 |
break; |
break; |
| 1372 |
default: |
default: |
| 1373 |
log_error("Unknown command %d\n", ret); |
log_error("Unknown command %d", ret); |
| 1374 |
} |
} |
| 1375 |
} |
} |
| 1376 |
|
|
| 1381 |
{ |
{ |
| 1382 |
MENU_SET ex_menu_set; |
MENU_SET ex_menu_set; |
| 1383 |
int ch = 0; |
int ch = 0; |
| 1384 |
|
int loop; |
| 1385 |
|
|
| 1386 |
if (p_section == NULL) |
if (p_section == NULL) |
| 1387 |
{ |
{ |
| 1388 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 1389 |
return -1; |
return -1; |
| 1390 |
} |
} |
| 1391 |
|
|
| 1400 |
|
|
| 1401 |
if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0) |
if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0) |
| 1402 |
{ |
{ |
| 1403 |
log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid); |
log_error("get_section_ex_menu_set(sid=%d) error", p_section->sid); |
| 1404 |
return -3; |
return -3; |
| 1405 |
} |
} |
| 1406 |
if (get_menu_shm_readonly(&ex_menu_set) < 0) |
if (get_menu_shm_readonly(&ex_menu_set) < 0) |
| 1407 |
{ |
{ |
| 1408 |
log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid); |
log_error("get_menu_shm_readonly(sid=%d) error", p_section->sid); |
| 1409 |
return -3; |
return -3; |
| 1410 |
} |
} |
| 1411 |
|
|
| 1414 |
|
|
| 1415 |
if (display_menu(&ex_menu_set) == 0) |
if (display_menu(&ex_menu_set) == 0) |
| 1416 |
{ |
{ |
| 1417 |
while (!SYS_server_exit) |
for (loop = 1; !SYS_server_exit && loop;) |
| 1418 |
{ |
{ |
| 1419 |
iflush(); |
iflush(); |
| 1420 |
ch = igetch(100); |
ch = igetch(100); |
| 1422 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 1423 |
{ |
{ |
| 1424 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 1425 |
|
|
| 1426 |
|
// Refresh current action |
| 1427 |
|
if (user_online_update(NULL) < 0) |
| 1428 |
|
{ |
| 1429 |
|
log_error("user_online_update(NULL) error"); |
| 1430 |
|
} |
| 1431 |
} |
} |
| 1432 |
|
|
| 1433 |
switch (ch) |
switch (ch) |
| 1434 |
{ |
{ |
| 1435 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 1436 |
log_error("KEY_NULL\n"); |
log_debug("KEY_NULL"); |
| 1437 |
return 0; |
loop = 0; |
| 1438 |
|
break; |
| 1439 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 1440 |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |
| 1441 |
{ |
{ |
| 1442 |
log_error("User input timeout\n"); |
log_debug("User input timeout"); |
| 1443 |
return 0; |
loop = 0; |
| 1444 |
|
break; |
| 1445 |
} |
} |
| 1446 |
continue; |
continue; |
| 1447 |
case CR: |
case CR: |
| 1449 |
switch (menu_control(&ex_menu_set, ch)) |
switch (menu_control(&ex_menu_set, ch)) |
| 1450 |
{ |
{ |
| 1451 |
case EXITMENU: |
case EXITMENU: |
| 1452 |
ch = EXITMENU; |
loop = 0; |
| 1453 |
break; |
break; |
| 1454 |
case REDRAW: |
case REDRAW: |
| 1455 |
clearscr(); |
clearscr(); |
| 1462 |
break; |
break; |
| 1463 |
} |
} |
| 1464 |
} |
} |
|
|
|
|
if (ch == EXITMENU) |
|
|
{ |
|
|
break; |
|
|
} |
|
| 1465 |
} |
} |
| 1466 |
} |
} |
| 1467 |
|
|
| 1481 |
|
|
| 1482 |
if ((fp = fopen(filename, "wb")) == NULL) |
if ((fp = fopen(filename, "wb")) == NULL) |
| 1483 |
{ |
{ |
| 1484 |
log_error("fopen(%s, wb) error: %d\n", filename, errno); |
log_error("fopen(%s, wb) error: %d", filename, errno); |
| 1485 |
return -1; |
return -1; |
| 1486 |
} |
} |
| 1487 |
|
|
| 1489 |
{ |
{ |
| 1490 |
if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1) |
if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1) |
| 1491 |
{ |
{ |
| 1492 |
log_error("fwrite(%s, sid) error\n", filename); |
log_error("fwrite(%s, sid) error", filename); |
| 1493 |
ret = -2; |
ret = -2; |
| 1494 |
break; |
break; |
| 1495 |
} |
} |
| 1496 |
|
|
| 1497 |
if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1) |
if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1) |
| 1498 |
{ |
{ |
| 1499 |
log_error("fwrite(%s, aid) error\n", filename); |
log_error("fwrite(%s, aid) error", filename); |
| 1500 |
ret = -2; |
ret = -2; |
| 1501 |
break; |
break; |
| 1502 |
} |
} |
| 1504 |
|
|
| 1505 |
if (fclose(fp) < 0) |
if (fclose(fp) < 0) |
| 1506 |
{ |
{ |
| 1507 |
log_error("fclose(%s) error: %d\n", filename, errno); |
log_error("fclose(%s) error: %d", filename, errno); |
| 1508 |
ret = -1; |
ret = -1; |
| 1509 |
} |
} |
| 1510 |
|
|
| 1529 |
{ |
{ |
| 1530 |
return 0; |
return 0; |
| 1531 |
} |
} |
| 1532 |
log_error("fopen(%s, rb) error: %d\n", filename, errno); |
log_error("fopen(%s, rb) error: %d", filename, errno); |
| 1533 |
return -1; |
return -1; |
| 1534 |
} |
} |
| 1535 |
|
|
| 1541 |
{ |
{ |
| 1542 |
break; |
break; |
| 1543 |
} |
} |
| 1544 |
log_error("fread(%s, sid) error: %d\n", filename, ferror(fp)); |
log_error("fread(%s, sid) error: %d", filename, ferror(fp)); |
| 1545 |
ret = -2; |
ret = -2; |
| 1546 |
break; |
break; |
| 1547 |
} |
} |
| 1552 |
{ |
{ |
| 1553 |
break; |
break; |
| 1554 |
} |
} |
| 1555 |
log_error("fread(%s, aid) error: %d\n", filename, ferror(fp)); |
log_error("fread(%s, aid) error: %d", filename, ferror(fp)); |
| 1556 |
ret = -2; |
ret = -2; |
| 1557 |
break; |
break; |
| 1558 |
} |
} |
| 1566 |
i = get_section_index(p_section); |
i = get_section_index(p_section); |
| 1567 |
if (i < 0) |
if (i < 0) |
| 1568 |
{ |
{ |
| 1569 |
log_error("get_section_index(sid=%d) error\n", sid); |
log_error("get_section_index(sid=%d) error", sid); |
| 1570 |
ret = -3; |
ret = -3; |
| 1571 |
break; |
break; |
| 1572 |
} |
} |
| 1575 |
|
|
| 1576 |
if (fclose(fp) < 0) |
if (fclose(fp) < 0) |
| 1577 |
{ |
{ |
| 1578 |
log_error("fclose(%s) error: %d\n", filename, errno); |
log_error("fclose(%s) error: %d", filename, errno); |
| 1579 |
ret = -1; |
ret = -1; |
| 1580 |
} |
} |
| 1581 |
|
|