Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/chsrc-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ chsrc_register_chefs_and_sauciers ()
chef_register_contributor ("@JIAFALSEDREAM", "假发", "jiafa@hello-happy.world", NULL);
chef_register_contributor ("@yayoinoyume", "YAYOI27", "yayoi27@yayoi.uk", NULL);

chef_register_contributor ("@lilyco-42", "Haoyu Zhou", "", "lilyco-42");
chef_register_contributor ("@YuruiHong", "Yurui Hong", "", "YuruiHong");

/**
* AI贡献者:
*
Expand Down
27 changes: 25 additions & 2 deletions src/framework/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* | @BingChunMoLi
* | @Mikachu2333
* | @JIAFALSEDREAM
* | @lilyco-42
* |
* Created On : <2023-08-29>
* Last Modified : <2026-08-20>
* Last Modified : <2026-11-29>
*
* 源的确定
* ------------------------------------------------------------*/
Expand Down Expand Up @@ -112,9 +113,31 @@ measure_speed_for_url (void *url)
static double
parse_and_say_curl_result (char *curl_buf)
{
/* curl 失败时可能无任何输出,此时须软处理而非崩溃。
* 理论上走不到这里:一旦触发,说明我们正在排查的 Bug 真实发生,请让用户报告以便定位。 */
if (NULL==curl_buf || '\0'==curl_buf[0])
{
char *msg = ENGLISH
? "ERROR curl output is empty (connection failed?). This is a bug under investigation, please report: chsrc issue"
: "错误 curl 无输出 (连接失败?)。这是我们正在排查的 Bug,请报告以便定位: chsrc issue";
println (red (msg));
return -1;
}

/* 分隔两部分数据 */
char *split = strchr (curl_buf, ' ');
if (split) *split = '\0';
if (NULL==split)
{
/* 输出不含空格,格式异常,软处理;同样请用户报告以便定位正在排查的 Bug */
char *msg = ENGLISH ? "ERROR malformed curl output: " : "错误 curl 输出格式异常: ";
char *report = ENGLISH
? " (This is a bug under investigation, please report: chsrc issue)"
: "(这是我们正在排查的 Bug,请报告以便定位: chsrc issue)";
println (red (xy_strcat (3, msg, curl_buf, report)));
return -1;
}

*split = '\0';

// say(curl_buf); say(split+1);
int http_code = xy_str2int (curl_buf);
Expand Down
14 changes: 14 additions & 0 deletions test/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "../src/framework/base.c"
#include "../src/framework/OS.c"
#include "../src/framework/dish.c"
#include "../src/framework/chef.c"
#include "../src/framework/source.c"

int
main (int argc, char const *argv[])
Expand All @@ -25,6 +28,17 @@ main (int argc, char const *argv[])

xy_init ();

char empty[] = "";
char malformed[] = "000";
char failed[] = "000 0";
char normal[] = "200 1024";
assert (parse_and_say_curl_result (NULL) == -1);
assert (parse_and_say_curl_result (empty) == -1);
assert (parse_and_say_curl_result (malformed) == -1);
assert (parse_and_say_curl_result (failed) == 0);
assert (parse_and_say_curl_result (normal) == 1024);


br();
chsrc_log ("chsrc_log");
chsrc_succ ("chsrc_succ");
Expand Down