fix: dont print body on stdout

This commit is contained in:
ngn 2024-05-09 23:35:44 +03:00
parent b8243e3ee9
commit 48d177965e
3 changed files with 27 additions and 12 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-09 23:17+0300\n" "POT-Creation-Date: 2024-05-09 23:28+0300\n"
"PO-Revision-Date: 2024-05-01 13:34+0300\n" "PO-Revision-Date: 2024-05-01 13:34+0300\n"
"Last-Translator: <ngn@ngn.tf>\n" "Last-Translator: <ngn@ngn.tf>\n"
"Language-Team: Turkish <gnome-turk@gnome.org>\n" "Language-Team: Turkish <gnome-turk@gnome.org>\n"
@ -254,26 +254,30 @@ msgid "Description"
msgstr "" msgstr ""
#: src/url.c:44 #: src/url.c:44
msgid "Failed to open /dev/null"
msgstr ""
#: src/url.c:51
msgid "Failed to init curl" msgid "Failed to init curl"
msgstr "" msgstr ""
#: src/url.c:55 #: src/url.c:63
msgid "Request failed" msgid "Request failed"
msgstr "" msgstr ""
#: src/url.c:62 #: src/url.c:70
msgid "Failed to get the response code" msgid "Failed to get the response code"
msgstr "" msgstr ""
#: src/url.c:68 #: src/url.c:76
msgid "Response is not a redirect" msgid "Response is not a redirect"
msgstr "" msgstr ""
#: src/url.c:75 #: src/url.c:83
msgid "Failed to get the location header" msgid "Failed to get the location header"
msgstr "" msgstr ""
#: src/url.c:81 #: src/url.c:89
msgid "Invalid location header" msgid "Invalid location header"
msgstr "" msgstr ""

View File

@ -19,12 +19,13 @@ enum ErrorCodes {
UrlCurlFail = 940, UrlCurlFail = 940,
UrlReqFail = 939, UrlReqFail = 939,
UrlNullFail = 938,
UrlReqCodeFail = 938, UrlReqCodeFail = 937,
UrlReqBadCode = 937, UrlReqBadCode = 936,
UrlLocationFail = 936, UrlLocationFail = 935,
UrlLocationBad = 935 UrlLocationBad = 934
}; };
extern int errno; extern int errno;

View File

@ -36,19 +36,27 @@ char *url_complete(char *name) {
char url[strlen(name) + strlen(HUB_URL) + 1]; char url[strlen(name) + strlen(HUB_URL) + 1];
sprintf(url, "%s/%s", HUB_URL, name); sprintf(url, "%s/%s", HUB_URL, name);
FILE *devnull = fopen("/dev/null", "w");
char *location = NULL; char *location = NULL;
long code = 0; long code = 0;
if (NULL == devnull) {
error_set(_("Failed to open /dev/null"));
errno = UrlNullFail;
return NULL;
}
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if (NULL == curl) { if (NULL == curl) {
error_set(_("Failed to init curl")); error_set(_("Failed to init curl"));
errno = UrlCurlFail; errno = UrlCurlFail;
return NULL; goto CLEANUP;
} }
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl/mp"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl/mp");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, devnull);
CURLcode res = curl_easy_perform(curl); CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) { if (res != CURLE_OK) {
@ -86,7 +94,9 @@ char *url_complete(char *name) {
location = strdup(location); location = strdup(location);
CLEANUP: CLEANUP:
curl_easy_cleanup(curl); fclose(devnull);
if (NULL != curl)
curl_easy_cleanup(curl);
return location; return location;
} }