Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024 #include "memdebug.h"
00025
00026
00027
00028
00029 #define TO "<recipient@example.com>"
00030 #define FROM "<sender@example.com>"
00031
00032 static const char *payload_text[] = {
00033 "From: different\r\n",
00034 "To: another\r\n",
00035 "\r\n",
00036 "\r\n",
00037 ".\r\n",
00038 ".\r\n",
00039 "\r\n",
00040 ".\r\n",
00041 "\r\n",
00042 "body",
00043 NULL
00044 };
00045
00046 struct upload_status {
00047 int lines_read;
00048 };
00049
00050 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00051 {
00052 struct upload_status *upload_ctx = (struct upload_status *)userp;
00053 const char *data;
00054
00055 if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
00056 return 0;
00057 }
00058
00059 data = payload_text[upload_ctx->lines_read];
00060
00061 if(data) {
00062 size_t len = strlen(data);
00063 memcpy(ptr, data, len);
00064 upload_ctx->lines_read++;
00065
00066 return len;
00067 }
00068
00069 return 0;
00070 }
00071
00072 int test(char *URL)
00073 {
00074 CURLcode res;
00075 CURL *curl;
00076 struct curl_slist *rcpt_list = NULL;
00077 struct upload_status upload_ctx = {0};
00078
00079 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00080 fprintf(stderr, "curl_global_init() failed\n");
00081 return TEST_ERR_MAJOR_BAD;
00082 }
00083
00084 curl = curl_easy_init();
00085 if(!curl) {
00086 fprintf(stderr, "curl_easy_init() failed\n");
00087 curl_global_cleanup();
00088 return TEST_ERR_MAJOR_BAD;
00089 }
00090
00091 rcpt_list = curl_slist_append(rcpt_list, TO);
00092
00093
00094
00095
00096 test_setopt(curl, CURLOPT_URL, URL);
00097 test_setopt(curl, CURLOPT_UPLOAD, 1L);
00098 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00099 test_setopt(curl, CURLOPT_READDATA, &upload_ctx);
00100 test_setopt(curl, CURLOPT_MAIL_FROM, FROM);
00101 test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
00102 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00103
00104 res = curl_easy_perform(curl);
00105
00106 test_cleanup:
00107
00108 curl_slist_free_all(rcpt_list);
00109 curl_easy_cleanup(curl);
00110 curl_global_cleanup();
00111
00112 return (int)res;
00113 }
00114
00115