lib1520.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 2014, Steve Holme, <steve_holme@hotmail.com>.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include "memdebug.h"
00025 
00026 /*
00027  * This is the list of basic details you need to tweak to get things right.
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   /* more addresses can be added here
00093      rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
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 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05