smtp-client
SMTP Client C Library
test.h
Go to the documentation of this file.
1 
30 #ifndef SMTP_TEST_H
31 #define SMTP_TEST_H
32 
33 #include <sys/select.h>
34 #include <sys/socket.h>
35 #include <sys/types.h>
36 
37 #include "../src/smtp.h"
38 
39 #ifdef SMTP_OPENSSL
40 # include <openssl/bio.h>
41 # include <openssl/err.h>
42 # include <openssl/ssl.h>
43 # include <openssl/x509.h>
44 # include <openssl/x509v3.h>
45 #endif /* SMTP_OPENSSL */
46 
47 struct smtp_command;
48 struct str_getdelimfd;
49 
50 int
51 smtp_si_add_size_t(const size_t a,
52  const size_t b,
53  size_t *const result);
54 
55 int
56 smtp_si_sub_size_t(const size_t a,
57  const size_t b,
58  size_t *const result);
59 
60 int
61 smtp_si_mul_size_t(const size_t a,
62  const size_t b,
63  size_t *const result);
64 
65 size_t
66 smtp_base64_decode(const char *const buf,
67  unsigned char **decode);
68 
69 char *
70 smtp_base64_encode(const char *const buf,
71  size_t buflen);
72 
73 char *
74 smtp_bin2hex(const unsigned char *const s,
75  size_t slen);
76 
78 smtp_write(struct smtp *const smtp,
79  const char *const buf,
80  size_t len);
81 
82 int
83 smtp_str_getdelimfd(struct str_getdelimfd *const gdfd);
84 
85 int
87  size_t copy_len);
88 
89 void
90 smtp_str_getdelimfd_free(struct str_getdelimfd *const gdfd);
91 
92 char *
93 smtp_stpcpy(char *s1,
94  const char *s2);
95 
96 void *
97 smtp_reallocarray(void *ptr,
98  size_t nmemb,
99  size_t size);
100 
101 char *
102 smtp_strdup(const char *s);
103 
104 char *
105 smtp_str_replace(const char *const search,
106  const char *const replace,
107  const char *const s);
108 
109 size_t
110 smtp_utf8_charlen(char c);
111 
112 int
113 smtp_str_has_nonascii_utf8(const char *const s);
114 
115 size_t
116 smtp_strnlen_utf8(const char *s,
117  size_t maxlen);
118 
119 size_t
120 smtp_fold_whitespace_get_offset(const char *const s,
121  unsigned int maxlen);
122 
123 char *
124 smtp_fold_whitespace(const char *const s,
125  unsigned int maxlen);
126 
127 char *
128 smtp_chunk_split(const char *const s,
129  size_t chunklen,
130  const char *const end);
131 
132 char *
133 smtp_ffile_get_contents(FILE *stream,
134  size_t *bytes_read);
135 
136 char *
137 smtp_file_get_contents(const char *const filename,
138  size_t *bytes_read);
139 
140 int
141 smtp_parse_cmd_line(char *const line,
142  struct smtp_command *const cmd);
143 
144 int
145 smtp_date_rfc_2822(char *const date);
146 
147 int
148 smtp_address_validate_email(const char *const email);
149 
150 int
151 smtp_address_validate_name(const char *const name);
152 
153 int
154 smtp_attachment_validate_name(const char *const name);
155 
156 int
157 smtp_header_key_validate(const char *const key);
158 
159 int
160 smtp_header_value_validate(const char *const value);
161 
162 /* test seams */
163 int
164 smtp_test_seam_dec_err_ctr(int *const test_err_ctr);
165 
166 BIO *
168  int close_flag);
169 
170 int
172 
173 void *
174 smtp_test_seam_calloc(size_t nelem,
175  size_t elsize);
176 
177 int
178 smtp_test_seam_close(int fildes);
179 
180 int
182  const struct sockaddr *address,
183  socklen_t address_len);
184 
185 unsigned long
187 
188 int
189 smtp_test_seam_fclose(FILE *stream);
190 
191 int
192 smtp_test_seam_ferror(FILE *stream);
193 
194 struct tm *
195 smtp_test_seam_gmtime_r(const time_t *timep,
196  struct tm *result);
197 
198 unsigned char *
199 smtp_test_seam_hmac(const EVP_MD *evp_md,
200  const void *key,
201  int key_len,
202  const unsigned char *d,
203  size_t n,
204  unsigned char *md,
205  unsigned int *md_len);
206 
207 struct tm *
208 smtp_test_seam_localtime_r(const time_t *timep,
209  struct tm *result);
210 
211 void *
212 smtp_test_seam_malloc(size_t size);
213 
214 time_t
215 smtp_test_seam_mktime(struct tm *timeptr);
216 
217 
218 void *
219 smtp_test_seam_realloc(void *ptr,
220  size_t size);
221 
222 long
224  void *buffer,
225  size_t length,
226  int flags);
227 
228 int
229 smtp_test_seam_select(int nfds,
230  fd_set *readfds,
231  fd_set *writefds,
232  fd_set *errorfds,
233  struct timeval *timeout);
234 
235 ssize_t
237  const void *buffer,
238  size_t length,
239  int flags);
240 
241 int
242 smtp_test_seam_socket(int domain,
243  int type,
244  int protocol);
245 
246 int
248 
249 SSL_CTX *
250 smtp_test_seam_ssl_ctx_new(const SSL_METHOD *method);
251 
252 int
254 
255 X509 *
257 
258 int
260  const char *name,
261  size_t namelen,
262  unsigned int flags,
263  char **peername);
264 
265 SSL *
266 smtp_test_seam_ssl_new(SSL_CTX *ctx);
267 
268 int
269 smtp_test_seam_ssl_read(SSL *ssl,
270  void *buf,
271  int num);
272 
273 int
274 smtp_test_seam_ssl_write(SSL *ssl,
275  const void *buf,
276  int num);
277 
278 int
279 smtp_test_seam_sprintf(char *s,
280  const char *format, ...);
281 
282 size_t
283 smtp_test_seam_strlen(const char *s);
284 
285 time_t
286 smtp_test_seam_time(time_t *tloc);
287 
294 
301 
310 
316 extern int g_smtp_test_err_calloc_ctr;
317 
323 extern int g_smtp_test_err_close_ctr;
324 
330 extern int g_smtp_test_err_connect_ctr;
331 
338 
344 extern int g_smtp_test_err_fclose_ctr;
345 
351 extern int g_smtp_test_err_ferror_ctr;
352 
359 
365 extern int g_smtp_test_err_hmac_ctr;
366 
373 
379 extern int g_smtp_test_err_malloc_ctr;
380 
386 extern int g_smtp_test_err_mktime_ctr;
387 
393 extern int g_smtp_test_err_realloc_ctr;
394 
400 extern int g_smtp_test_err_recv_ctr;
401 
409 extern int g_smtp_test_err_recv_rc;
410 
420 extern char g_smtp_test_err_recv_bytes[90];
421 
427 extern int g_smtp_test_err_select_ctr;
428 
434 extern int g_smtp_test_err_send_ctr;
435 
439 extern int g_smtp_test_send_one_byte;
440 
447 
454 
461 
467 extern int g_smtp_test_err_socket_ctr;
468 
475 
482 
489 
496 
503 
509 extern int g_smtp_test_err_ssl_new_ctr;
510 
517 
524 
530 extern int g_smtp_test_err_sprintf_ctr;
531 
538 extern int g_smtp_test_err_sprintf_rc;
539 
549 
556 extern size_t g_smtp_test_strlen_ret_value;
557 
566 extern int g_smtp_test_time_custom_ret;
567 
574 extern time_t g_smtp_test_time_ret_value;
575 
576 #endif /* SMTP_TEST_H */
577 
int g_smtp_test_err_si_sub_size_t_ctr
Definition: seams.c:143
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_recv_ctr
Definition: seams.c:106
int g_smtp_test_err_sprintf_ctr
Definition: seams.c:204
long smtp_test_seam_recv(int socket, void *buffer, size_t length, int flags)
Definition: seams.c:513
int smtp_test_seam_ssl_do_handshake(SSL *ssl)
Definition: seams.c:654
int smtp_date_rfc_2822(char *const date)
Definition: smtp.c:2236
int smtp_parse_cmd_line(char *const line, struct smtp_command *const cmd)
Definition: smtp.c:1467
char * smtp_fold_whitespace(const char *const s, unsigned int maxlen)
Definition: smtp.c:1250
int g_smtp_test_err_ssl_do_handshake_ctr
Definition: seams.c:172
int smtp_address_validate_name(const char *const name)
Definition: smtp.c:2903
int g_smtp_test_err_gmtime_r_ctr
Definition: seams.c:75
int g_smtp_test_err_malloc_ctr
Definition: seams.c:91
int g_smtp_test_err_bio_should_retry_rc
Definition: seams.c:39
char * smtp_stpcpy(char *s1, const char *s2)
Definition: smtp.c:599
int g_smtp_test_err_close_ctr
Definition: seams.c:49
int smtp_str_getdelimfd(struct str_getdelimfd *const gdfd)
Definition: smtp.c:523
size_t smtp_strnlen_utf8(const char *s, size_t maxlen)
Definition: smtp.c:1138
int smtp_test_seam_ssl_connect(SSL *ssl)
Definition: seams.c:624
ssize_t smtp_test_seam_send(int socket, const void *buffer, size_t length, int flags)
Definition: seams.c:575
struct tm * smtp_test_seam_localtime_r(const time_t *timep, struct tm *result)
Definition: seams.c:444
int g_smtp_test_err_calloc_ctr
Definition: seams.c:44
enum smtp_status_code smtp_write(struct smtp *const smtp, const char *const buf, size_t len)
Definition: smtp.c:1603
int g_smtp_test_err_err_peek_error_ctr
Definition: seams.c:60
int smtp_header_key_validate(const char *const key)
Definition: smtp.c:2822
int smtp_test_seam_ssl_read(SSL *ssl, void *buf, int num)
Definition: seams.c:726
int smtp_str_getdelimfd_set_line_and_buf(struct str_getdelimfd *const gdfd, size_t copy_len)
Definition: smtp.c:457
int g_smtp_test_err_connect_ctr
Definition: seams.c:54
int smtp_test_seam_sprintf(char *s, const char *format,...)
Definition: seams.c:771
int g_smtp_test_err_localtime_r_ctr
Definition: seams.c:86
int smtp_test_seam_x509_check_host(X509 *cert, const char *name, size_t namelen, unsigned int flags, char **peername)
Definition: seams.c:690
int g_smtp_test_err_ssl_read_ctr
Definition: seams.c:194
void * smtp_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition: smtp.c:622
int smtp_test_seam_fclose(FILE *stream)
Definition: seams.c:365
X509 * smtp_test_seam_ssl_get_peer_certificate(const SSL *ssl)
Definition: seams.c:669
int smtp_test_seam_bio_should_retry(BIO *bio)
Definition: seams.c:279
char * smtp_bin2hex(const unsigned char *const s, size_t slen)
Definition: smtp.c:1031
int g_smtp_test_err_ssl_new_ctr
Definition: seams.c:189
size_t smtp_fold_whitespace_get_offset(const char *const s, unsigned int maxlen)
Definition: smtp.c:1179
SSL * smtp_test_seam_ssl_new(SSL_CTX *ctx)
Definition: seams.c:709
char * line
Definition: smtp.h:592
time_t g_smtp_test_time_ret_value
Definition: seams.c:229
int g_smtp_test_err_bio_new_socket_ctr
Definition: seams.c:28
size_t smtp_utf8_charlen(char c)
Definition: smtp.c:1078
int g_smtp_test_err_send_ctr
Definition: seams.c:126
int smtp_test_seam_ferror(FILE *stream)
Definition: seams.c:382
#define socket
Definition: seams.h:193
BIO * smtp_test_seam_bio_new_socket(int sock, int close_flag)
Definition: seams.c:263
smtp_status_code
Definition: smtp.h:32
time_t smtp_test_seam_time(time_t *tloc)
Definition: seams.c:813
int g_smtp_test_err_recv_rc
Definition: seams.c:111
int smtp_test_seam_close(int fildes)
Definition: seams.c:315
void smtp_str_getdelimfd_free(struct str_getdelimfd *const gdfd)
Definition: smtp.c:489
size_t g_smtp_test_strlen_ret_value
Definition: seams.c:219
int g_smtp_test_err_bio_should_retry_ctr
Definition: seams.c:34
int smtp_test_seam_ssl_write(SSL *ssl, const void *buf, int num)
Definition: seams.c:753
int smtp_attachment_validate_name(const char *const name)
Definition: smtp.c:2927
int g_smtp_test_err_si_mul_size_t_ctr
Definition: seams.c:149
int smtp_si_mul_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:320
int smtp_test_seam_connect(int socket, const struct sockaddr *address, socklen_t address_len)
Definition: seams.c:333
int g_smtp_test_err_si_add_size_t_ctr
Definition: seams.c:137
int g_smtp_test_err_realloc_ctr
Definition: seams.c:101
char * smtp_base64_encode(const char *const buf, size_t buflen)
Definition: smtp.c:825
int smtp_address_validate_email(const char *const email)
Definition: smtp.c:2878
SSL_CTX * smtp_test_seam_ssl_ctx_new(const SSL_METHOD *method)
Definition: seams.c:639
int g_smtp_test_err_mktime_ctr
Definition: seams.c:96
int g_smtp_test_send_one_byte
Definition: seams.c:131
int g_smtp_test_err_hmac_ctr
Definition: seams.c:80
int g_smtp_test_err_ferror_ctr
Definition: seams.c:70
int g_smtp_test_err_fclose_ctr
Definition: seams.c:65
int g_smtp_test_err_ssl_get_peer_certificate_ctr
Definition: seams.c:178
char * smtp_chunk_split(const char *const s, size_t chunklen, const char *const end)
Definition: smtp.c:1312
int g_smtp_test_strlen_custom_ret
Definition: seams.c:214
int smtp_test_seam_socket(int domain, int type, int protocol)
Definition: seams.c:606
Definition: smtp.c:150
size_t smtp_base64_decode(const char *const buf, unsigned char **decode)
Definition: smtp.c:984
void * smtp_test_seam_malloc(size_t size)
Definition: seams.c:460
int smtp_test_seam_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
Definition: seams.c:552
struct tm * smtp_test_seam_gmtime_r(const time_t *timep, struct tm *result)
Definition: seams.c:399
char * smtp_file_get_contents(const char *const filename, size_t *bytes_read)
Definition: smtp.c:1439
unsigned long smtp_test_seam_err_peek_error(void)
Definition: seams.c:351
unsigned char * smtp_test_seam_hmac(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d, size_t n, unsigned char *md, unsigned int *md_len)
Definition: seams.c:421
int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
char * smtp_ffile_get_contents(FILE *stream, size_t *bytes_read)
Definition: smtp.c:1386
int smtp_header_value_validate(const char *const value)
Definition: smtp.c:2852
int smtp_si_sub_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:286
int g_smtp_test_err_ssl_connect_ctr
Definition: seams.c:160
time_t smtp_test_seam_mktime(struct tm *timeptr)
Definition: seams.c:476
int g_smtp_test_err_socket_ctr
Definition: seams.c:154
int g_smtp_test_err_ssl_ctx_new_ctr
Definition: seams.c:166
size_t smtp_test_seam_strlen(const char *s)
Definition: seams.c:793
char g_smtp_test_err_recv_bytes[90]
Definition: seams.c:116
void * smtp_test_seam_realloc(void *ptr, size_t size)
Definition: seams.c:493
void * smtp_test_seam_calloc(size_t nelem, size_t elsize)
Definition: seams.c:298
int g_smtp_test_err_ssl_write_ctr
Definition: seams.c:199
int g_smtp_test_err_x509_check_host_ctr
Definition: seams.c:184
int g_smtp_test_time_custom_ret
Definition: seams.c:224
int smtp_str_has_nonascii_utf8(const char *const s)
Definition: smtp.c:1110
int g_smtp_test_err_select_ctr
Definition: seams.c:121
char * smtp_str_replace(const char *const search, const char *const replace, const char *const s)
Definition: smtp.c:679
int g_smtp_test_err_sprintf_rc
Definition: seams.c:209
char * smtp_strdup(const char *s)
Definition: smtp.c:650