diff options
Diffstat (limited to 'xs_curl.h')
| -rw-r--r-- | xs_curl.h | 36 |
1 files changed, 36 insertions, 0 deletions
| @@ -9,6 +9,9 @@ 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 | |||
| 12 | #ifdef XS_IMPLEMENTATION | 15 | #ifdef XS_IMPLEMENTATION |
| 13 | 16 | ||
| 14 | #include <curl/curl.h> | 17 | #include <curl/curl.h> |
| @@ -194,6 +197,39 @@ xs_dict *xs_http_request(const char *method, const char *url, | |||
| 194 | return response; | 197 | return response; |
| 195 | } | 198 | } |
| 196 | 199 | ||
| 200 | 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 | { | ||
| 203 | CURL *curl; | ||
| 204 | CURLcode res = CURLE_OK; | ||
| 205 | struct curl_slist *rcpt = NULL; | ||
| 206 | struct _payload_data pd = { | ||
| 207 | .data = (char *)body, | ||
| 208 | .size = xs_size(body), | ||
| 209 | .offset = 0 | ||
| 210 | }; | ||
| 211 | |||
| 212 | curl = curl_easy_init(); | ||
| 213 | |||
| 214 | curl_easy_setopt(curl, CURLOPT_URL, url); | ||
| 215 | curl_easy_setopt(curl, CURLOPT_USERNAME, user); | ||
| 216 | curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); | ||
| 217 | |||
| 218 | curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); | ||
| 219 | curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt = curl_slist_append(rcpt, to)); | ||
| 220 | |||
| 221 | curl_easy_setopt(curl, CURLOPT_READDATA, &pd); | ||
| 222 | curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback); | ||
| 223 | curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); | ||
| 224 | |||
| 225 | res = curl_easy_perform(curl); | ||
| 226 | |||
| 227 | curl_slist_free_all(rcpt); | ||
| 228 | curl_easy_cleanup(curl); | ||
| 229 | |||
| 230 | return (int)res; | ||
| 231 | } | ||
| 232 | |||
| 197 | #endif /* XS_IMPLEMENTATION */ | 233 | #endif /* XS_IMPLEMENTATION */ |
| 198 | 234 | ||
| 199 | #endif /* _XS_CURL_H */ | 235 | #endif /* _XS_CURL_H */ |