Reduce expression complexity

This commit is contained in:
Michał Trojnara 2023-01-15 22:09:08 +01:00
parent c4ec6debe5
commit a862378280

View File

@ -1082,28 +1082,36 @@ static int add_timestamp(PKCS7 *sig, char *url, char *proxy, int rfc3161,
/* Start a libcurl easy session and set options for a curl easy handle */ /* Start a libcurl easy session and set options for a curl easy handle */
curl = curl_easy_init(); curl = curl_easy_init();
if (proxy) { if (proxy) {
if ((res = curl_easy_setopt(curl, CURLOPT_PROXY, proxy)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
if (!strncmp("http:", proxy, 5) && if (!strncmp("http:", proxy, 5)) {
(res = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
}
} }
if (!strncmp("socks:", proxy, 6) && if (!strncmp("socks:", proxy, 6)) {
(res = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
}
} }
} }
if ((res = curl_easy_setopt(curl, CURLOPT_URL, url)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_URL, url);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
/* /*
* ask libcurl to show us the verbose output * ask libcurl to show us the verbose output
* curl_easy_setopt(curl, CURLOPT_VERBOSE, 42); * curl_easy_setopt(curl, CURLOPT_VERBOSE, 42);
*/ */
if ((noverifypeer) && if (noverifypeer) {
(res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
}
} }
if (rfc3161) { if (rfc3161) {
@ -1115,7 +1123,8 @@ static int add_timestamp(PKCS7 *sig, char *url, char *proxy, int rfc3161,
} }
slist = curl_slist_append(slist, "User-Agent: Transport"); slist = curl_slist_append(slist, "User-Agent: Transport");
slist = curl_slist_append(slist, "Cache-Control: no-cache"); slist = curl_slist_append(slist, "Cache-Control: no-cache");
if ((res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
@ -1128,22 +1137,27 @@ static int add_timestamp(PKCS7 *sig, char *url, char *proxy, int rfc3161,
if (!bout) if (!bout)
return 1; /* FAILED */ return 1; /* FAILED */
len = BIO_get_mem_data(bout, &p); len = BIO_get_mem_data(bout, &p);
if ((res = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
if ((res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char*)p)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char*)p);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
bin = BIO_new(BIO_s_mem()); bin = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(bin, 0); BIO_set_mem_eof_return(bin, 0);
if ((res = curl_easy_setopt(curl, CURLOPT_POST, 1)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_POST, 1);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
if ((res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, bin)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, bin);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
if ((res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write)) != CURLE_OK) { res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
if (res != CURLE_OK) {
printf("CURL failure: %s %s\n", curl_easy_strerror(res), url); printf("CURL failure: %s %s\n", curl_easy_strerror(res), url);
} }
/* Perform the request */ /* Perform the request */