/[LeafOK_CVS]/lbbs/src/section_list_display.c
ViewVC logotype

Diff of /lbbs/src/section_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.58 by sysadm, Wed Oct 29 01:48:46 2025 UTC Revision 1.71 by sysadm, Wed Nov 5 01:04:06 2025 UTC
# Line 1  Line 1 
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-2025  Leaflet <leaflet@leafok.com>
7     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "article_cache.h"  #include "article_cache.h"
10  #include "article_favor.h"  #include "article_favor.h"
# Line 31  Line 23 
23  #include "screen.h"  #include "screen.h"
24  #include "str_process.h"  #include "str_process.h"
25  #include "user_info_display.h"  #include "user_info_display.h"
26    #include "user_list_display.h"
27  #include "user_priv.h"  #include "user_priv.h"
28    #include <ctype.h>
29    #include <errno.h>
30  #include <string.h>  #include <string.h>
31  #include <time.h>  #include <time.h>
32  #include <sys/param.h>  #include <sys/param.h>
33    
34  static int section_aid_locations[BBS_max_section] = {0};  #define TITLE_SEARCH_MAX_LEN 60
35    
36    static int32_t section_aid_locations[BBS_max_section] = {0};
37  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
38  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
39    
# Line 56  enum select_cmd_t Line 53  enum select_cmd_t
53          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
54          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
55          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
56            LAST_SECTION_ARTICLE,
57          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
58            SCAN_ARTICLE_BACKWARD_BY_USER,
59            SCAN_ARTICLE_FORWARD_BY_USER,
60            SCAN_ARTICLE_BACKWARD_BY_TITLE,
61            SCAN_ARTICLE_FORWARD_BY_TITLE,
62          VIEW_EX_DIR,          VIEW_EX_DIR,
63          SHOW_TOP10,          SHOW_TOP10,
64            SEARCH_USER,
65  };  };
66    
67  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, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 268  static enum select_cmd_t section_list_se Line 271  static enum select_cmd_t section_list_se
271                          log_error("KEY_NULL\n");                          log_error("KEY_NULL\n");
272                          return EXIT_SECTION;                          return EXIT_SECTION;
273                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
274                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
275                          {                          {
276                                  log_error("User input timeout\n");                                  log_error("User input timeout\n");
277                                  return EXIT_SECTION;                                  return EXIT_SECTION;
# Line 358  static enum select_cmd_t section_list_se Line 361  static enum select_cmd_t section_list_se
361                          break;                          break;
362                  case '$':                  case '$':
363                  case KEY_END:                  case KEY_END:
364                            if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list
365                            {
366                                    return LAST_SECTION_ARTICLE;
367                            }
368                          if (total_page > 0)                          if (total_page > 0)
369                          {                          {
370                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
# Line 406  static enum select_cmd_t section_list_se Line 413  static enum select_cmd_t section_list_se
413                                  return SCAN_NEW_ARTICLE;                                  return SCAN_NEW_ARTICLE;
414                          }                          }
415                          break;                          break;
416                    case 'A':
417                            if (item_count > 0)
418                            {
419                                    return SCAN_ARTICLE_BACKWARD_BY_USER;
420                            }
421                            break;
422                    case 'a':
423                            if (item_count > 0)
424                            {
425                                    return SCAN_ARTICLE_FORWARD_BY_USER;
426                            }
427                            break;
428                    case '?':
429                            if (item_count > 0)
430                            {
431                                    return SCAN_ARTICLE_BACKWARD_BY_TITLE;
432                            }
433                            break;
434                    case '/':
435                            if (item_count > 0)
436                            {
437                                    return SCAN_ARTICLE_FORWARD_BY_TITLE;
438                            }
439                            break;
440                    case 'u':
441                            return SEARCH_USER;
442                  case 'h':                  case 'h':
443                          return SHOW_HELP;                          return SHOW_HELP;
444                  case 'x':                  case 'x':
# Line 558  int section_list_display(const char *sna Line 591  int section_list_display(const char *sna
591          int page_id_cur;          int page_id_cur;
592          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
593          USER_INFO user_info;          USER_INFO user_info;
594            char user_intro[BBS_user_intro_max_len + 1];
595            char username[BBS_username_max_len + 1];
596            char username_list[1][BBS_username_max_len + 1];
597            int32_t uid;
598            int i;
599            int ok;
600            char title[BBS_article_title_max_len + 1] = "\0";
601    
602          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
603          if (p_section == NULL)          if (p_section == NULL)
# Line 660  int section_list_display(const char *sna Line 700  int section_list_display(const char *sna
700                  }                  }
701    
702                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
703    
704                  switch (ret)                  switch (ret)
705                  {                  {
706                  case EXIT_SECTION:                  case EXIT_SECTION:
707                            // Update current aid location
708                            if (p_articles[selected_index] != NULL)
709                            {
710                                    if (selected_index >= ontop_start_offset)
711                                    {
712                                            ret = last_article_in_section(p_section, &p_article_locate);
713                                            if (ret < 0)
714                                            {
715                                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
716                                                    return -3;
717                                            }
718                                            else if (ret == 0)
719                                            {
720                                                    section_aid_locations[section_index] = 0;
721                                            }
722                                            else // ret > 0
723                                            {
724                                                    section_aid_locations[section_index] = p_article_locate->aid;
725                                            }
726                                    }
727                                    else
728                                    {
729                                            section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
730                                    }
731                            }
732                          return 0;                          return 0;
733                  case CHANGE_PAGE:                  case CHANGE_PAGE:
734                          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);
# Line 807  int section_list_display(const char *sna Line 873  int section_list_display(const char *sna
873                                          {                                          {
874                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
875                                          }                                          }
876                                            else if (ret > 0) // Article replied
877                                            {
878                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
879                                                    if (ret < 0)
880                                                    {
881                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
882                                                            return -3;
883                                                    }
884                                            }
885                                          loop = 1;                                          loop = 1;
886                                          break;                                          break;
887                                  case '=':  // First topic article                                  case '=':  // First topic article
# Line 841  int section_list_display(const char *sna Line 916  int section_list_display(const char *sna
916                          // Update current topic                          // Update current topic
917                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
918    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
919                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
920                          {                          {
921                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 873  int section_list_display(const char *sna Line 945  int section_list_display(const char *sna
945                                  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);
946                                  if (ret < 0)                                  if (ret < 0)
947                                  {                                  {
948                                          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: %d\n", p_section->sid, page_id, ret);
949                                          return -3;                                          return -3;
950                                  }                                  }
951                          }                          }
# Line 899  int section_list_display(const char *sna Line 971  int section_list_display(const char *sna
971                          {                          {
972                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
973                          }                          }
974                            else if (ret > 0) // Article modified
975                            {
976                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
977                                    if (ret < 0)
978                                    {
979                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
980                                            return -3;
981                                    }
982                            }
983                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
984                          {                          {
985                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 917  int section_list_display(const char *sna Line 998  int section_list_display(const char *sna
998                          }                          }
999                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
1000                          {                          {
1001                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
1002                                  {                                  {
1003                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1004                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
1005                                  }                                          {
1006                                                    selected_index = article_count - 1;
1007                                                    break;
1008                                            }
1009                                            else if (ret < 0 && page_id > 0)
1010                                            {
1011                                                    page_id--;
1012                                                    selected_index = BBS_article_limit_per_page - 1;
1013                                            }
1014                                            else if (ret < 0 && page_id <= 0)
1015                                            {
1016                                                    selected_index = 0;
1017                                                    break;
1018                                            }
1019                                    } while (ret < 0);
1020                          }                          }
1021                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1022                          {                          {
# Line 942  int section_list_display(const char *sna Line 1036  int section_list_display(const char *sna
1036                          }                          }
1037                          break;                          break;
1038                  case QUERY_USER:                  case QUERY_USER:
1039                          if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info)) < 0)                          if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)
1040                          {                          {
1041                                  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\n", p_articles[selected_index]->uid);
1042                                  return -2;                                  return -2;
# Line 1008  int section_list_display(const char *sna Line 1102  int section_list_display(const char *sna
1102                                  }                                  }
1103                          }                          }
1104                          break;                          break;
1105                    case LAST_SECTION_ARTICLE:
1106                            page_id_cur = page_id;
1107                            ret = last_article_in_section(p_section, &p_article_locate);
1108                            if (ret < 0)
1109                            {
1110                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
1111                                    return -3;
1112                            }
1113                            else if (ret == 0)
1114                            {
1115                                    break;
1116                            }
1117                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1118                                                                                            &page_id, &selected_index, &article_count);
1119                            if (ret < 0)
1120                            {
1121                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1122                                                      p_section->sid, p_article_locate->aid);
1123                                    return -3;
1124                            }
1125                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1126                            {
1127                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1128                                    if (ret < 0)
1129                                    {
1130                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1131                                            return -3;
1132                                    }
1133                            }
1134                            break;
1135                  case SCAN_NEW_ARTICLE:                  case SCAN_NEW_ARTICLE:
1136                          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);
1137                          if (ret < 0)                          if (ret < 0)
# Line 1039  int section_list_display(const char *sna Line 1163  int section_list_display(const char *sna
1163                                  }                                  }
1164                          }                          }
1165                          break;                          break;
1166                    case SCAN_ARTICLE_BACKWARD_BY_USER:
1167                    case SCAN_ARTICLE_FORWARD_BY_USER:
1168                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_USER ? 1 : -1);
1169                            strncpy(username, p_articles[selected_index]->username, sizeof(username) - 1);
1170                            username[sizeof(username) - 1] = '\0';
1171                            uid = 0;
1172    
1173                            moveto(SCREEN_ROWS, 1);
1174                            clrtoeol();
1175                            get_data(SCREEN_ROWS, 1,
1176                                             (direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "),
1177                                             username, sizeof(username), BBS_username_max_len);
1178    
1179                            if (username[0] == '\0')
1180                            {
1181                                    break;
1182                            }
1183    
1184                            // Verify format
1185                            for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1186                            {
1187                                    if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))
1188                                    {
1189                                            ok = 0;
1190                                    }
1191                            }
1192                            if (ok && i > BBS_username_max_len)
1193                            {
1194                                    ok = 0;
1195                            }
1196                            if (!ok)
1197                            {
1198                                    break;
1199                            }
1200    
1201                            ret = query_user_info_by_username(username, 1, &uid, username_list);
1202                            if (ret < 0)
1203                            {
1204                                    log_error("query_user_info_by_username(%s) error\n", username);
1205                                    break;
1206                            }
1207    
1208                            if (uid > 0)
1209                            {
1210                                    ret = scan_article_in_section_by_uid(p_section, p_articles[selected_index],
1211                                                                                                             direction, uid, &p_article_locate);
1212                                    if (ret < 0)
1213                                    {
1214                                            log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n",
1215                                                              p_section->sid, p_articles[selected_index]->aid, direction, uid);
1216                                            return -3;
1217                                    }
1218                                    else if (ret == 0) // not found
1219                                    {
1220                                            break;
1221                                    }
1222                            }
1223                            else // uid == 0
1224                            {
1225                                    ret = scan_article_in_section_by_username(p_section, p_articles[selected_index],
1226                                                                                                                      direction, username, &p_article_locate);
1227                                    if (ret < 0)
1228                                    {
1229                                            log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n",
1230                                                              p_section->sid, p_articles[selected_index]->aid, direction, username);
1231                                            return -3;
1232                                    }
1233                                    else if (ret == 0) // not found
1234                                    {
1235                                            break;
1236                                    }
1237                            }
1238    
1239                            page_id_cur = page_id;
1240                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1241                                                                                            &page_id, &selected_index, &article_count);
1242                            if (ret < 0)
1243                            {
1244                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1245                                                      p_section->sid, p_article_locate->aid);
1246                                    return -3;
1247                            }
1248                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1249                            {
1250                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1251                                    if (ret < 0)
1252                                    {
1253                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1254                                            return -3;
1255                                    }
1256                            }
1257                            break;
1258                    case SCAN_ARTICLE_BACKWARD_BY_TITLE:
1259                    case SCAN_ARTICLE_FORWARD_BY_TITLE:
1260                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1);
1261    
1262                            moveto(SCREEN_ROWS, 1);
1263                            clrtoeol();
1264                            get_data(SCREEN_ROWS, 1,
1265                                             (direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "),
1266                                             title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1267    
1268                            if (title[0] == '\0')
1269                            {
1270                                    break;
1271                            }
1272    
1273                            ret = scan_article_in_section_by_title(p_section, p_articles[selected_index],
1274                                                                                                       direction, title, &p_article_locate);
1275                            if (ret < 0)
1276                            {
1277                                    log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n",
1278                                                      p_section->sid, p_articles[selected_index]->aid, direction, title);
1279                                    return -3;
1280                            }
1281                            else if (ret == 0) // not found
1282                            {
1283                                    break;
1284                            }
1285    
1286                            page_id_cur = page_id;
1287                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1288                                                                                            &page_id, &selected_index, &article_count);
1289                            if (ret < 0)
1290                            {
1291                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1292                                                      p_section->sid, p_article_locate->aid);
1293                                    return -3;
1294                            }
1295                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1296                            {
1297                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1298                                    if (ret < 0)
1299                                    {
1300                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1301                                            return -3;
1302                                    }
1303                            }
1304                            break;
1305                    case SEARCH_USER:
1306                            user_list_search();
1307                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1308                            {
1309                                    log_error("section_list_draw_screen() error\n");
1310                                    return -2;
1311                            }
1312                            break;
1313                  case SHOW_HELP:                  case SHOW_HELP:
1314                          // Display help information                          // Display help information
1315                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 1127  int section_list_ex_dir_display(SECTION_ Line 1398  int section_list_ex_dir_display(SECTION_
1398                                  log_error("KEY_NULL\n");                                  log_error("KEY_NULL\n");
1399                                  return 0;                                  return 0;
1400                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1401                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
1402                                  {                                  {
1403                                          log_error("User input timeout\n");                                          log_error("User input timeout\n");
1404                                          return 0;                                          return 0;
# Line 1163  int section_list_ex_dir_display(SECTION_ Line 1434  int section_list_ex_dir_display(SECTION_
1434    
1435          return 0;          return 0;
1436  }  }
1437    
1438    int section_aid_locations_save(int uid)
1439    {
1440            char filename[FILE_PATH_LEN];
1441            FILE *fp;
1442            int i;
1443            int ret = 0;
1444    
1445            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1446    
1447            if ((fp = fopen(filename, "wb")) == NULL)
1448            {
1449                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1450                    return -1;
1451            }
1452    
1453            for (i = 0; i < p_section_list_pool->section_count; i++)
1454            {
1455                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1456                    {
1457                            log_error("fwrite(%s, sid) error\n", filename);
1458                            ret = -2;
1459                            break;
1460                    }
1461    
1462                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1463                    {
1464                            log_error("fwrite(%s, aid) error\n", filename);
1465                            ret = -2;
1466                            break;
1467                    }
1468            }
1469    
1470            if (fclose(fp) < 0)
1471            {
1472                    log_error("fclose(%s) error: %d\n", filename, errno);
1473                    ret = -1;
1474            }
1475    
1476            return ret;
1477    }
1478    
1479    int section_aid_locations_load(int uid)
1480    {
1481            char filename[FILE_PATH_LEN];
1482            FILE *fp;
1483            int i;
1484            int32_t sid;
1485            int32_t aid;
1486            SECTION_LIST *p_section;
1487            int ret = 0;
1488    
1489            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1490    
1491            if ((fp = fopen(filename, "rb")) == NULL)
1492            {
1493                    if (errno == ENOENT) // file not exist
1494                    {
1495                            return 0;
1496                    }
1497                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1498                    return -1;
1499            }
1500    
1501            while (!feof(fp))
1502            {
1503                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1504                    {
1505                            if (ferror(fp) == 0)
1506                            {
1507                                    break;
1508                            }
1509                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1510                            ret = -2;
1511                            break;
1512                    }
1513    
1514                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1515                    {
1516                            if (ferror(fp) == 0)
1517                            {
1518                                    break;
1519                            }
1520                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1521                            ret = -2;
1522                            break;
1523                    }
1524    
1525                    p_section = section_list_find_by_sid(sid);
1526                    if (p_section == NULL)
1527                    {
1528                            continue; // skip section no longer exist
1529                    }
1530    
1531                    i = get_section_index(p_section);
1532                    if (i < 0)
1533                    {
1534                            log_error("get_section_index(sid=%d) error\n", sid);
1535                            ret = -3;
1536                            break;
1537                    }
1538                    section_aid_locations[i] = aid;
1539            }
1540    
1541            if (fclose(fp) < 0)
1542            {
1543                    log_error("fclose(%s) error: %d\n", filename, errno);
1544                    ret = -1;
1545            }
1546    
1547            return ret;
1548    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1