diff options
Diffstat (limited to 'xs_curl.h')
| -rw-r--r-- | xs_curl.h | 47 |
1 files changed, 47 insertions, 0 deletions
| @@ -9,6 +9,10 @@ xs_dict *xs_http_request(const char *method, const char *url, | |||
| 9 | const xs_str *body, int b_size, int *status, | 9 | const xs_str *body, int b_size, int *status, |
| 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, | ||
| 13 | const char *from, const char *to, const xs_str *body, | ||
| 14 | int use_ssl); | ||
| 15 | |||
| 12 | const char *xs_curl_strerr(int errnum); | 16 | const char *xs_curl_strerr(int errnum); |
| 13 | 17 | ||
| 14 | #ifdef XS_IMPLEMENTATION | 18 | #ifdef XS_IMPLEMENTATION |
| @@ -197,6 +201,49 @@ xs_dict *xs_http_request(const char *method, const char *url, | |||
| 197 | } | 201 | } |
| 198 | 202 | ||
| 199 | 203 | ||
| 204 | int xs_smtp_request(const char *url, const char *user, const char *pass, | ||
| 205 | const char *from, const char *to, const xs_str *body, | ||
| 206 | int use_ssl) | ||
| 207 | { | ||
| 208 | CURL *curl; | ||
| 209 | CURLcode res = CURLE_OK; | ||
| 210 | struct curl_slist *rcpt = NULL; | ||
| 211 | struct _payload_data pd = { | ||
| 212 | .data = (char *)body, | ||
| 213 | .size = strlen(body), | ||
| 214 | .offset = 0 | ||
| 215 | }; | ||
| 216 | |||
| 217 | curl = curl_easy_init(); | ||
| 218 | |||
| 219 | curl_easy_setopt(curl, CURLOPT_URL, url); | ||
| 220 | if (user && pass) { | ||
| 221 | /* allow authless connections, to, e.g. localhost */ | ||
| 222 | curl_easy_setopt(curl, CURLOPT_USERNAME, user); | ||
| 223 | curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); | ||
| 224 | } | ||
| 225 | |||
| 226 | if (use_ssl) | ||
| 227 | curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); | ||
| 228 | |||
| 229 | curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); | ||
| 230 | |||
| 231 | rcpt = curl_slist_append(rcpt, to); | ||
| 232 | curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt); | ||
| 233 | |||
| 234 | curl_easy_setopt(curl, CURLOPT_READDATA, &pd); | ||
| 235 | curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback); | ||
| 236 | curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); | ||
| 237 | |||
| 238 | res = curl_easy_perform(curl); | ||
| 239 | |||
| 240 | curl_easy_cleanup(curl); | ||
| 241 | curl_slist_free_all(rcpt); | ||
| 242 | |||
| 243 | return (int)res; | ||
| 244 | } | ||
| 245 | |||
| 246 | |||
| 200 | const char *xs_curl_strerr(int errnum) | 247 | const char *xs_curl_strerr(int errnum) |
| 201 | { | 248 | { |
| 202 | CURLcode cc = errnum < 0 ? -errnum : errnum; | 249 | CURLcode cc = errnum < 0 ? -errnum : errnum; |