embedded-framework/utils/Servers/src/curl_serve.c
2024-02-28 03:49:11 -08:00

52 lines
2.1 KiB
C

/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "curl_serve.h"
static ServerInit gCurlServe;
void SetVerboseLog(LogFlag flag) { gCurlServe.logFlag = flag; }
void SetSslVerify(SslFlag flag) { gCurlServe.sslVerifyFlag = flag; }
CURL *CurlEasyMake(void)
{
CURL *curl;
curl = curl_easy_init();
if (!curl) {
return curl;
}
if (SSL_VERIFY_DISABLE == gCurlServe.sslVerifyFlag) {
/*
* If you want to connect to a site who is not using a certificate that is
* signed by one of the certs in the CA bundle you have, you can skip the
* verification of the server's certificate. This makes the connection
* A LOT LESS SECURE.
*
* If you have a CA cert for the server stored someplace else than in the
* default bundle, then the CURLOPT_CAPATH option might come handy for
* you.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
/*
* If the site you are connecting to uses a different host name that what
* they have mentioned in their server certificate's commonName (or
* subjectAltName) fields, libcurl will refuse to connect. You can skip
* this check, but this will make the connection less secure.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
}
if (LOG_FLAG_ENABLE == gCurlServe.logFlag) {
/* Switch on full protocol/debug output */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}
return curl;
}