/[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.3 by sysadm, Sat Jun 7 10:00:10 2025 UTC Revision 1.14 by sysadm, Wed Oct 15 03:10:47 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_view_log.h"  #include "article_view_log.h"
 #include "log.h"  
18  #include "common.h"  #include "common.h"
19  #include "database.h"  #include "database.h"
20    #include "log.h"
21  #include <stdlib.h>  #include <stdlib.h>
   
 #define _XOPEN_SOURCE 500  
 #define _POSIX_C_SOURCE 200809L  
22  #include <string.h>  #include <string.h>
23    
24  ARTICLE_VIEW_LOG BBS_article_view_log;  ARTICLE_VIEW_LOG BBS_article_view_log;
# Line 35  int article_view_log_load(int uid, ARTIC Line 32  int article_view_log_load(int uid, ARTIC
32    
33          if (p_view_log == NULL)          if (p_view_log == NULL)
34          {          {
35                  log_error("article_view_log_load() error: NULL pointer\n");                  log_error("NULL pointer error\n");
36                  return -1;                  return -1;
37          }          }
38    
# Line 107  int article_view_log_unload(ARTICLE_VIEW Line 104  int article_view_log_unload(ARTICLE_VIEW
104  {  {
105          if (p_view_log == NULL)          if (p_view_log == NULL)
106          {          {
107                  log_error("article_view_log_unload() error: NULL pointer\n");                  log_error("NULL pointer error\n");
108                  return -1;                  return -1;
109          }          }
110    
# Line 123  int article_view_log_unload(ARTICLE_VIEW Line 120  int article_view_log_unload(ARTICLE_VIEW
120    
121  int article_view_log_save_inc(const ARTICLE_VIEW_LOG *p_view_log)  int article_view_log_save_inc(const ARTICLE_VIEW_LOG *p_view_log)
122  {  {
123          MYSQL *db;          MYSQL *db = NULL;
124          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
125          char tuple_tmp[LINE_BUFFER_LEN];          char tuple_tmp[LINE_BUFFER_LEN];
126          int i;          int i;
# Line 131  int article_view_log_save_inc(const ARTI Line 128  int article_view_log_save_inc(const ARTI
128    
129          if (p_view_log == NULL)          if (p_view_log == NULL)
130          {          {
131                  log_error("article_view_log_save_inc() error: NULL pointer\n");                  log_error("NULL pointer error\n");
132                  return -1;                  return -1;
133          }          }
134    
135          if (p_view_log->uid <= 0)          if (p_view_log->uid <= 0 || p_view_log->aid_inc_cnt == 0)
136          {          {
137                  return 0;                  return 0;
138          }          }
# Line 161  int article_view_log_save_inc(const ARTI Line 158  int article_view_log_save_inc(const ARTI
158                          if (mysql_query(db, sql) != 0)                          if (mysql_query(db, sql) != 0)
159                          {                          {
160                                  log_error("Add view_article_log error: %s\n", mysql_error(db));                                  log_error("Add view_article_log error: %s\n", mysql_error(db));
161                                    mysql_close(db);
162                                  return -3;                                  return -3;
163                          }                          }
164    
# Line 187  int article_view_log_merge_inc(ARTICLE_V Line 185  int article_view_log_merge_inc(ARTICLE_V
185          int32_t *aid_new;          int32_t *aid_new;
186          int aid_new_cnt;          int aid_new_cnt;
187          int i, j, k;          int i, j, k;
188            int len;
189    
190          if (p_view_log == NULL)          if (p_view_log == NULL)
191          {          {
192                  log_error("article_view_log_merge_inc() error: NULL pointer\n");                  log_error("NULL pointer error\n");
193                  return -1;                  return -1;
194          }          }
195    
# Line 227  int article_view_log_merge_inc(ARTICLE_V Line 226  int article_view_log_merge_inc(ARTICLE_V
226                  }                  }
227          }          }
228    
229          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;
230          k += (p_view_log->aid_base_cnt - i);          if (len > 0)
231          memcpy(aid_new + k, p_view_log->aid_inc + j, sizeof(int32_t) * (size_t)(p_view_log->aid_inc_cnt - j));          {
232          k += (p_view_log->aid_inc_cnt - j);                  memcpy(aid_new + k, p_view_log->aid_base + i,
233                               sizeof(int32_t) * (size_t)len);
234                    k += len;
235            }
236            len = p_view_log->aid_inc_cnt - j;
237            if (len > 0)
238            {
239                    memcpy(aid_new + k, p_view_log->aid_inc + j,
240                               sizeof(int32_t) * (size_t)len);
241                    k += len;
242            }
243    
244          free(p_view_log->aid_base);          free(p_view_log->aid_base);
245          p_view_log->aid_base = aid_new;          p_view_log->aid_base = aid_new;
# Line 250  int article_view_log_is_viewed(int32_t a Line 259  int article_view_log_is_viewed(int32_t a
259    
260          if (p_view_log == NULL)          if (p_view_log == NULL)
261          {          {
262                  log_error("article_view_log_is_viewed() error: NULL pointer\n");                  log_error("NULL pointer error\n");
263                  return -1;                  return -1;
264          }          }
265    
# Line 299  int article_view_log_set_viewed(int32_t Line 308  int article_view_log_set_viewed(int32_t
308    
309          if (p_view_log == NULL)          if (p_view_log == NULL)
310          {          {
311                  log_error("article_view_log_set_viewed() error: NULL pointer\n");                  log_error("NULL pointer error\n");
312                  return -1;                  return -1;
313          }          }
314    
# Line 337  int article_view_log_set_viewed(int32_t Line 346  int article_view_log_set_viewed(int32_t
346          }          }
347    
348          // Merge if Inc is full          // Merge if Inc is full
349          if (p_view_log->aid_inc_cnt >= MAX_AID_INC_CNT)          if (p_view_log->aid_inc_cnt >= MAX_VIEWED_AID_INC_CNT)
350          {          {
351                  // Save incremental article view log                  // Save incremental article view log
352                  if (article_view_log_save_inc(p_view_log) < 0)                  if (article_view_log_save_inc(p_view_log) < 0)
# Line 362  int article_view_log_set_viewed(int32_t Line 371  int article_view_log_set_viewed(int32_t
371                  right = left + 1;                  right = left + 1;
372          }          }
373    
374          for (i = p_view_log->aid_inc_cnt - 1; i >= right; i--)          if (p_view_log->aid_inc_cnt > right)
375          {          {
376                  p_view_log->aid_inc[i + 1] = p_view_log->aid_inc[i];                  memmove(p_view_log->aid_inc + right + 1,
377                                    p_view_log->aid_inc + right,
378                                    sizeof(int32_t) * (size_t)(p_view_log->aid_inc_cnt - right));
379          }          }
380    
381          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