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

Diff of /lbbs/src/article_view_log.c

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

Revision 1.8 by sysadm, Mon Oct 13 00:18:40 2025 UTC Revision 1.18 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                           article_view_log.c  -  description  /*
3                                                           -------------------   * article_view_log
4          Copyright            : (C) 2004-2025 by Leaflet   *   - data persistence and query of article view log
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  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_view_log.h"  #include "article_view_log.h"
14  #include "common.h"  #include "common.h"
# Line 32  int article_view_log_load(int uid, ARTIC Line 28  int article_view_log_load(int uid, ARTIC
28    
29          if (p_view_log == NULL)          if (p_view_log == NULL)
30          {          {
31                  log_error("article_view_log_load() error: NULL pointer\n");                  log_error("NULL pointer error\n");
32                  return -1;                  return -1;
33          }          }
34    
# Line 104  int article_view_log_unload(ARTICLE_VIEW Line 100  int article_view_log_unload(ARTICLE_VIEW
100  {  {
101          if (p_view_log == NULL)          if (p_view_log == NULL)
102          {          {
103                  log_error("article_view_log_unload() error: NULL pointer\n");                  log_error("NULL pointer error\n");
104                  return -1;                  return -1;
105          }          }
106    
# Line 128  int article_view_log_save_inc(const ARTI Line 124  int article_view_log_save_inc(const ARTI
124    
125          if (p_view_log == NULL)          if (p_view_log == NULL)
126          {          {
127                  log_error("article_view_log_save_inc() error: NULL pointer\n");                  log_error("NULL pointer error\n");
128                  return -1;                  return -1;
129          }          }
130    
131          if (p_view_log->uid <= 0)          if (p_view_log->uid <= 0 || p_view_log->aid_inc_cnt == 0)
132          {          {
133                  return 0;                  return 0;
134          }          }
# Line 185  int article_view_log_merge_inc(ARTICLE_V Line 181  int article_view_log_merge_inc(ARTICLE_V
181          int32_t *aid_new;          int32_t *aid_new;
182          int aid_new_cnt;          int aid_new_cnt;
183          int i, j, k;          int i, j, k;
184            int len;
185    
186          if (p_view_log == NULL)          if (p_view_log == NULL)
187          {          {
188                  log_error("article_view_log_merge_inc() error: NULL pointer\n");                  log_error("NULL pointer error\n");
189                  return -1;                  return -1;
190          }          }
191    
# Line 225  int article_view_log_merge_inc(ARTICLE_V Line 222  int article_view_log_merge_inc(ARTICLE_V
222                  }                  }
223          }          }
224    
225          memcpy(aid_new + k, p_view_log->aid_base + i, sizeof(int32_t) * (size_t)(p_view_log->aid_base_cnt - i));          len = p_view_log->aid_base_cnt - i;
226          k += (p_view_log->aid_base_cnt - i);          if (len > 0)
227          memcpy(aid_new + k, p_view_log->aid_inc + j, sizeof(int32_t) * (size_t)(p_view_log->aid_inc_cnt - j));          {
228          k += (p_view_log->aid_inc_cnt - j);                  memcpy(aid_new + k, p_view_log->aid_base + i,
229                               sizeof(int32_t) * (size_t)len);
230                    k += len;
231            }
232            len = p_view_log->aid_inc_cnt - j;
233            if (len > 0)
234            {
235                    memcpy(aid_new + k, p_view_log->aid_inc + j,
236                               sizeof(int32_t) * (size_t)len);
237                    k += len;
238            }
239    
240          free(p_view_log->aid_base);          free(p_view_log->aid_base);
241          p_view_log->aid_base = aid_new;          p_view_log->aid_base = aid_new;
# Line 248  int article_view_log_is_viewed(int32_t a Line 255  int article_view_log_is_viewed(int32_t a
255    
256          if (p_view_log == NULL)          if (p_view_log == NULL)
257          {          {
258                  log_error("article_view_log_is_viewed() error: NULL pointer\n");                  log_error("NULL pointer error\n");
259                  return -1;                  return -1;
260          }          }
261    
# Line 267  int article_view_log_is_viewed(int32_t a Line 274  int article_view_log_is_viewed(int32_t a
274                          mid = (left + right) / 2;                          mid = (left + right) / 2;
275                          if (aid < (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))                          if (aid < (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))
276                          {                          {
277                                  right = mid;                                  right = mid - 1;
278                          }                          }
279                          else if (aid > (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))                          else if (aid > (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))
280                          {                          {
# Line 297  int article_view_log_set_viewed(int32_t Line 304  int article_view_log_set_viewed(int32_t
304    
305          if (p_view_log == NULL)          if (p_view_log == NULL)
306          {          {
307                  log_error("article_view_log_set_viewed() error: NULL pointer\n");                  log_error("NULL pointer error\n");
308                  return -1;                  return -1;
309          }          }
310    
# Line 316  int article_view_log_set_viewed(int32_t Line 323  int article_view_log_set_viewed(int32_t
323                          mid = (left + right) / 2;                          mid = (left + right) / 2;
324                          if (aid < (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))                          if (aid < (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))
325                          {                          {
326                                  right = mid;                                  right = mid - 1;
327                          }                          }
328                          else if (aid > (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))                          else if (aid > (i == 0 ? p_view_log->aid_base[mid] : p_view_log->aid_inc[mid]))
329                          {                          {
# Line 360  int article_view_log_set_viewed(int32_t Line 367  int article_view_log_set_viewed(int32_t
367                  right = left + 1;                  right = left + 1;
368          }          }
369    
370          for (i = p_view_log->aid_inc_cnt - 1; i >= right; i--)          if (p_view_log->aid_inc_cnt > right)
371          {          {
372                  p_view_log->aid_inc[i + 1] = p_view_log->aid_inc[i];                  memmove(p_view_log->aid_inc + right + 1,
373                                    p_view_log->aid_inc + right,
374                                    sizeof(int32_t) * (size_t)(p_view_log->aid_inc_cnt - right));
375          }          }
376    
377          p_view_log->aid_inc[right] = aid;          p_view_log->aid_inc[right] = aid;


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

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