diff options
| author | 2025-01-24 22:24:05 +0100 | |
|---|---|---|
| committer | 2025-01-24 22:24:05 +0100 | |
| commit | 3d96c576287736ebdf87e4a7b956842a6c6e055f (patch) | |
| tree | ad5f4cc5ebc9913ccfd753edfc934b82e34be72e /xs_curl.h | |
| parent | add tests subdirectory with makefile target (diff) | |
| download | penes-snac2-3d96c576287736ebdf87e4a7b956842a6c6e055f.tar.gz penes-snac2-3d96c576287736ebdf87e4a7b956842a6c6e055f.tar.xz penes-snac2-3d96c576287736ebdf87e4a7b956842a6c6e055f.zip | |
enforce tls when supported && add tests
Diffstat (limited to 'xs_curl.h')
| -rw-r--r-- | xs_curl.h | 22 |
1 files changed, 16 insertions, 6 deletions
| @@ -10,7 +10,8 @@ xs_dict *xs_http_request(const char *method, const char *url, | |||
| 10 | xs_str **payload, int *p_size, int timeout); | 10 | xs_str **payload, int *p_size, int timeout); |
| 11 | 11 | ||
| 12 | int xs_smtp_request(const char *url, const char *user, const char *pass, | 12 | int xs_smtp_request(const char *url, const char *user, const char *pass, |
| 13 | const char *from, const char *to, const xs_str *body); | 13 | const char *from, const char *to, const xs_str *body, |
| 14 | int use_ssl); | ||
| 14 | 15 | ||
| 15 | #ifdef XS_IMPLEMENTATION | 16 | #ifdef XS_IMPLEMENTATION |
| 16 | 17 | ||
| @@ -198,7 +199,8 @@ xs_dict *xs_http_request(const char *method, const char *url, | |||
| 198 | } | 199 | } |
| 199 | 200 | ||
| 200 | int xs_smtp_request(const char *url, const char *user, const char *pass, | 201 | int xs_smtp_request(const char *url, const char *user, const char *pass, |
| 201 | const char *from, const char *to, const xs_str *body) | 202 | const char *from, const char *to, const xs_str *body, |
| 203 | int use_ssl) | ||
| 202 | { | 204 | { |
| 203 | CURL *curl; | 205 | CURL *curl; |
| 204 | CURLcode res = CURLE_OK; | 206 | CURLcode res = CURLE_OK; |
| @@ -212,11 +214,19 @@ int xs_smtp_request(const char *url, const char *user, const char *pass, | |||
| 212 | curl = curl_easy_init(); | 214 | curl = curl_easy_init(); |
| 213 | 215 | ||
| 214 | curl_easy_setopt(curl, CURLOPT_URL, url); | 216 | curl_easy_setopt(curl, CURLOPT_URL, url); |
| 215 | curl_easy_setopt(curl, CURLOPT_USERNAME, user); | 217 | if (user && pass) { |
| 216 | curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); | 218 | /* allow authless connections, to, e.g. localhost */ |
| 219 | curl_easy_setopt(curl, CURLOPT_USERNAME, user); | ||
| 220 | curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); | ||
| 221 | } | ||
| 222 | |||
| 223 | if (use_ssl) | ||
| 224 | curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); | ||
| 217 | 225 | ||
| 218 | curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); | 226 | curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); |
| 219 | curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt = curl_slist_append(rcpt, to)); | 227 | |
| 228 | rcpt = curl_slist_append(rcpt, to); | ||
| 229 | curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt); | ||
| 220 | 230 | ||
| 221 | curl_easy_setopt(curl, CURLOPT_READDATA, &pd); | 231 | curl_easy_setopt(curl, CURLOPT_READDATA, &pd); |
| 222 | curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback); | 232 | 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, | |||
| 224 | 234 | ||
| 225 | res = curl_easy_perform(curl); | 235 | res = curl_easy_perform(curl); |
| 226 | 236 | ||
| 227 | curl_slist_free_all(rcpt); | ||
| 228 | curl_easy_cleanup(curl); | 237 | curl_easy_cleanup(curl); |
| 238 | curl_slist_free_all(rcpt); | ||
| 229 | 239 | ||
| 230 | return (int)res; | 240 | return (int)res; |
| 231 | } | 241 | } |