chsrc/src/framework/struct.h

128 lines
4.0 KiB
C
Raw Normal View History

2024-11-21 14:59:05 +08:00
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
2024-11-22 07:02:21 +08:00
* File Name : struct.h
2024-11-21 14:59:05 +08:00
* File Authors : Aoran Zeng <ccmywish@qq.com>
* | Heng Guo <2085471348@qq.com>
* Contributors : Shengwei Chen <414685209@qq.com>
* |
* Created On : <2023-08-29>
* Last Modified : <2024-11-21>
*
* chsrc struct
* ------------------------------------------------------------*/
typedef struct SpeedMeasureInfo_t
{
2024-11-22 09:58:00 +08:00
bool skip; /* 是否默认跳过 */
char *skip_reason_CN; /* 跳过的原因(中文)*/
char *skip_reason_EN; /* 跳过的原因(英文)*/
char *url; /* 测速链接 */
2024-11-21 14:59:05 +08:00
}
2024-11-22 07:02:21 +08:00
SpeedMeasureInfo_t;
2024-11-21 14:59:05 +08:00
#define SKIP true
#define NotSkip false
#define ToFill NULL
#define NA NULL
2024-11-22 06:23:23 +08:00
typedef struct SourceProvider_t
2024-11-21 14:59:05 +08:00
{
2024-11-22 06:23:23 +08:00
const char *code; /* 用于用户指定某一 Provider */
const char *abbr; /* 需要使用 Provider 的英文名时,用这个代替,因为大部分 Provider 没有提供正式的英文名 */
const char *name; /* Provider 中文名 */
const char *site; /* Provider 首页 */
2024-11-22 07:02:21 +08:00
SpeedMeasureInfo_t smi;
2024-11-21 14:59:05 +08:00
}
2024-11-22 07:02:21 +08:00
SourceProvider_t;
2024-11-22 06:23:23 +08:00
2024-11-22 07:02:21 +08:00
typedef SourceProvider_t MirrorSite_t;
2024-11-22 06:23:23 +08:00
2024-11-22 11:43:18 +08:00
SourceProvider_t UpstreamProvider =
{
2024-11-22 06:23:23 +08:00
"upstream", "Upstream", "上游默认源", NULL,
{SKIP, "上游默认源不测速", "SKIP for upstream source", NULL}
2024-11-22 11:43:18 +08:00
},
2024-11-22 06:23:23 +08:00
2024-11-22 11:43:18 +08:00
UserDefinedProvider =
{
2024-11-22 06:23:23 +08:00
"user", "用户自定义", "用户自定义", NULL,
{SKIP, "用户自定义源不测速", "SKIP for user-defined source", NULL}
};
2024-11-21 14:59:05 +08:00
2024-11-22 07:02:21 +08:00
typedef struct Source_t
2024-11-21 14:59:05 +08:00
{
2024-11-22 07:26:23 +08:00
union {
2024-11-22 09:58:00 +08:00
SourceProvider_t *provider;
MirrorSite_t *mirror;
2024-11-22 07:26:23 +08:00
};
2024-11-22 09:58:00 +08:00
char *url;
2024-11-21 14:59:05 +08:00
}
2024-11-22 07:02:21 +08:00
Source_t;
2024-11-21 14:59:05 +08:00
#define def_sources_n(t) const size_t t##_sources_n = xy_arylen(t##_sources)
2024-11-22 07:07:29 +08:00
2024-11-22 07:02:21 +08:00
enum Capability_t
2024-11-21 14:59:05 +08:00
{
CanNot,
FullyCan,
PartiallyCan
};
2024-11-22 07:07:29 +08:00
/* Target Feature */
typedef struct Feature_t
2024-11-21 14:59:05 +08:00
{
bool can_get;
bool can_reset; /* 有的reset不是暂时没有实现而是现在的实现根本就无法重置 */
bool can_english;
bool can_user_define; /* 用户自定义换源URL */
2024-11-22 07:02:21 +08:00
enum Capability_t cap_locally;
2024-11-21 14:59:05 +08:00
char *cap_locally_explain;
char *note;
}
2024-11-22 07:07:29 +08:00
Feature_t;
2024-11-21 14:59:05 +08:00
2024-11-22 07:07:29 +08:00
typedef struct Target_t
2024-11-21 14:59:05 +08:00
{
void (*getfn) (char *option);
void (*setfn) (char *option);
void (*resetfn) (char *option);
2024-11-22 07:07:29 +08:00
Feature_t (*featfn) (char *option);
2024-11-21 14:59:05 +08:00
2024-11-22 07:02:21 +08:00
Source_t *sources;
2024-11-22 07:07:29 +08:00
size_t sources_n;
2024-11-21 14:59:05 +08:00
}
2024-11-22 07:07:29 +08:00
Target_t;
2024-11-21 14:59:05 +08:00
#define def_target_inner_s(t) NULL, t##_setsrc, NULL, NULL
#define def_target_inner_sr(t) NULL, t##_setsrc, t##_resetsrc, NULL
#define def_target_inner_sf(t) NULL, t##_setsrc, NULL, t##_feat
#define def_target_inner_srf(t) NULL, t##_setsrc, t##_resetsrc, t##_feat
#define def_target_inner_gs(t) t##_getsrc, t##_setsrc, NULL, NULL
#define def_target_inner_gsr(t) t##_getsrc, t##_setsrc, t##_resetsrc, NULL
#define def_target_inner_gsf(t) t##_getsrc, t##_setsrc, NULL, t##_feat
#define def_target_inner_gsrf(t) t##_getsrc, t##_setsrc, t##_resetsrc, t##_feat
#define def_target_sourcesn(t) t##_sources, t##_sources_n
2024-11-22 07:26:23 +08:00
/* 大部分target还不支持reset所以暂时先默认设置为NULL来过渡 */
2024-11-22 07:07:29 +08:00
#define def_target(t) Target_t t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)}
#define def_target_s(t) Target_t t##_target = {def_target_inner_s(t),def_target_sourcesn(t)}
#define def_target_sr(t) Target_t t##_target = {def_target_inner_sr(t),def_target_sourcesn(t)}
#define def_target_sf(t) Target_t t##_target = {def_target_inner_sf(t),def_target_sourcesn(t)}
#define def_target_srf(t) Target_t t##_target = {def_target_inner_srf(t),def_target_sourcesn(t)}
#define def_target_gs(t) Target_t t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)}
#define def_target_gsr(t) Target_t t##_target = {def_target_inner_gsr(t),def_target_sourcesn(t)}
#define def_target_gsf(t) Target_t t##_target = {def_target_inner_gsf(t),def_target_sourcesn(t)}
#define def_target_gsrf(t) Target_t t##_target = {def_target_inner_gsrf(t),def_target_sourcesn(t)}