| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
article_favor.c - description |
/* |
| 3 |
------------------- |
* article_favor |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - data model and basic operations of user favorite articles |
| 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_favor.h" |
#include "article_favor.h" |
| 14 |
#include "common.h" |
#include "common.h" |
| 317 |
mid = (left + right) / 2; |
mid = (left + right) / 2; |
| 318 |
if (aid < (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
if (aid < (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
| 319 |
{ |
{ |
| 320 |
right = mid; |
right = mid - 1; |
| 321 |
} |
} |
| 322 |
else if (aid > (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
else if (aid > (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
| 323 |
{ |
{ |
| 368 |
mid = (left + right) / 2; |
mid = (left + right) / 2; |
| 369 |
if (aid < (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
if (aid < (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
| 370 |
{ |
{ |
| 371 |
right = mid; |
right = mid - 1; |
| 372 |
} |
} |
| 373 |
else if (aid > (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
else if (aid > (i == 0 ? p_favor->aid_base[mid] : p_favor->aid_inc[mid])) |
| 374 |
{ |
{ |
| 445 |
return 1; // Set complete |
return 1; // Set complete |
| 446 |
} |
} |
| 447 |
|
|
| 448 |
int query_favor_articles(ARTICLE_FAVOR *p_favor, int page_id, ARTICLE **p_articles, |
int query_favor_articles(ARTICLE_FAVOR *p_favor, int page_id, const ARTICLE **p_articles, |
| 449 |
char p_snames[][BBS_section_name_max_len + 1], int *p_article_count, int *p_page_count) |
char p_snames[][BBS_section_name_max_len + 1], int *p_article_count, int *p_page_count) |
| 450 |
{ |
{ |
| 451 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 469 |
return -2; |
return -2; |
| 470 |
} |
} |
| 471 |
|
|
| 472 |
*p_page_count = p_favor->aid_base_cnt / BBS_article_limit_per_page + (p_favor->aid_base_cnt % BBS_article_limit_per_page == 0 ? 0 : 1); |
*p_page_count = (p_favor->aid_base_cnt + BBS_article_limit_per_page - 1) / BBS_article_limit_per_page; |
| 473 |
*p_article_count = 0; |
*p_article_count = 0; |
| 474 |
|
|
| 475 |
if (p_favor->aid_base_cnt == 0) |
if (p_favor->aid_base_cnt == 0) |
| 504 |
return -3; |
return -3; |
| 505 |
} |
} |
| 506 |
|
|
| 507 |
// acquire lock of section |
if (get_section_info(p_section, p_snames[i], NULL, NULL) < 0) |
|
if (section_list_rd_lock(p_section) < 0) |
|
| 508 |
{ |
{ |
| 509 |
log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); |
log_error("get_section_info(sid=%d) error\n", p_section->sid); |
|
return -4; |
|
|
} |
|
|
|
|
|
memcpy(p_snames[i], p_section->sname, sizeof(p_snames[i])); |
|
|
|
|
|
// release lock of section |
|
|
if (section_list_rd_unlock(p_section) < 0) |
|
|
{ |
|
|
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
|
| 510 |
return -4; |
return -4; |
| 511 |
} |
} |
| 512 |
} |
} |