lib1520.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2014, Steve Holme, <steve_holme@hotmail.com>.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "test.h"
23 
24 #include "memdebug.h"
25 
26 /*
27  * This is the list of basic details you need to tweak to get things right.
28  */
29 #define TO "<recipient@example.com>"
30 #define FROM "<sender@example.com>"
31 
32 static const char *payload_text[] = {
33  "From: different\r\n",
34  "To: another\r\n",
35  "\r\n",
36  "\r\n",
37  ".\r\n",
38  ".\r\n",
39  "\r\n",
40  ".\r\n",
41  "\r\n",
42  "body",
43  NULL
44 };
45 
46 struct upload_status {
47  int lines_read;
48 };
49 
50 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
51 {
52  struct upload_status *upload_ctx = (struct upload_status *)userp;
53  const char *data;
54 
55  if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
56  return 0;
57  }
58 
59  data = payload_text[upload_ctx->lines_read];
60 
61  if(data) {
62  size_t len = strlen(data);
63  memcpy(ptr, data, len);
64  upload_ctx->lines_read++;
65 
66  return len;
67  }
68 
69  return 0;
70 }
71 
72 int test(char *URL)
73 {
74  CURLcode res;
75  CURL *curl;
76  struct curl_slist *rcpt_list = NULL;
77  struct upload_status upload_ctx = {0};
78 
80  fprintf(stderr, "curl_global_init() failed\n");
81  return TEST_ERR_MAJOR_BAD;
82  }
83 
84  curl = curl_easy_init();
85  if(!curl) {
86  fprintf(stderr, "curl_easy_init() failed\n");
88  return TEST_ERR_MAJOR_BAD;
89  }
90 
91  rcpt_list = curl_slist_append(rcpt_list, TO);
92  /* more addresses can be added here
93  rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
94  */
95 
96  test_setopt(curl, CURLOPT_URL, URL);
97  test_setopt(curl, CURLOPT_UPLOAD, 1L);
98  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
99  test_setopt(curl, CURLOPT_READDATA, &upload_ctx);
100  test_setopt(curl, CURLOPT_MAIL_FROM, FROM);
101  test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
102  test_setopt(curl, CURLOPT_VERBOSE, 1L);
103 
104  res = curl_easy_perform(curl);
105 
106 test_cleanup:
107 
108  curl_slist_free_all(rcpt_list);
109  curl_easy_cleanup(curl);
111 
112  return (int)res;
113 }
114 
115 
#define test_setopt(A, B, C)
Definition: test.h:47
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURLcode
Definition: curl.h:454
static int res
size_t len
Definition: curl_sasl.c:55
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
memcpy(filename, filename1, strlen(filename1))
CURL_EXTERN struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: slist.c:89
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
UNITTEST_START struct Curl_easy data
Definition: unit1399.c:82
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
#define TO
Definition: lib1520.c:29
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
Definition: lib1520.c:50
#define FROM
Definition: lib1520.c:30
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
Definition: easy.c:271
void CURL
Definition: curl.h:102
int test(char *URL)
Definition: lib1520.c:72
size_t size
Definition: unit1302.c:52
#define fprintf
Definition: curl_printf.h:41
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
static const char * payload_text[]
Definition: lib1520.c:32
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
Definition: slist.c:129
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15