aboutsummaryrefslogtreecommitdiff
path: root/xs_curl.h
diff options
context:
space:
mode:
authorshtrophic <christoph@liebender.dev>2025-01-24 22:24:05 +0100
committershtrophic <christoph@liebender.dev>2025-01-24 22:24:05 +0100
commit3d96c576287736ebdf87e4a7b956842a6c6e055f (patch)
treead5f4cc5ebc9913ccfd753edfc934b82e34be72e /xs_curl.h
parent1c4c15540360a5db9d56e6ae8d206a1f30a4f52b (diff)
enforce tls when supported && add tests
Diffstat (limited to 'xs_curl.h')
-rw-r--r--xs_curl.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/xs_curl.h b/xs_curl.h
index 886aee0..d98ac4c 100644
--- a/xs_curl.h
+++ b/xs_curl.h
@@ -10,7 +10,8 @@ xs_dict *xs_http_request(const char *method, const char *url,
xs_str **payload, int *p_size, int timeout);
int xs_smtp_request(const char *url, const char *user, const char *pass,
- const char *from, const char *to, const xs_str *body);
+ const char *from, const char *to, const xs_str *body,
+ int use_ssl);
#ifdef XS_IMPLEMENTATION
@@ -198,7 +199,8 @@ xs_dict *xs_http_request(const char *method, const char *url,
}
int xs_smtp_request(const char *url, const char *user, const char *pass,
- const char *from, const char *to, const xs_str *body)
+ const char *from, const char *to, const xs_str *body,
+ int use_ssl)
{
CURL *curl;
CURLcode res = CURLE_OK;
@@ -212,11 +214,19 @@ int xs_smtp_request(const char *url, const char *user, const char *pass,
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_USERNAME, user);
- curl_easy_setopt(curl, CURLOPT_PASSWORD, pass);
+ if (user && pass) {
+ /* allow authless connections, to, e.g. localhost */
+ curl_easy_setopt(curl, CURLOPT_USERNAME, user);
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, pass);
+ }
+
+ if (use_ssl)
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
- curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt = curl_slist_append(rcpt, to));
+
+ rcpt = curl_slist_append(rcpt, to);
+ curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt);
curl_easy_setopt(curl, CURLOPT_READDATA, &pd);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback);
@@ -224,8 +234,8 @@ int xs_smtp_request(const char *url, const char *user, const char *pass,
res = curl_easy_perform(curl);
- curl_slist_free_all(rcpt);
curl_easy_cleanup(curl);
+ curl_slist_free_all(rcpt);
return (int)res;
}