smtp-client
SMTP Client C Library
test.h File Reference

Test the smtp-client library. More...

#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "../src/smtp.h"
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
+ Include dependency graph for test.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int smtp_si_add_size_t (const size_t a, const size_t b, size_t *const result)
 
int smtp_si_sub_size_t (const size_t a, const size_t b, size_t *const result)
 
int smtp_si_mul_size_t (const size_t a, const size_t b, size_t *const result)
 
size_t smtp_base64_decode (const char *const buf, unsigned char **decode)
 
char * smtp_base64_encode (const char *const buf, size_t buflen)
 
char * smtp_bin2hex (const unsigned char *const s, size_t slen)
 
enum smtp_status_code smtp_write (struct smtp *const smtp, const char *const buf, size_t len)
 
int smtp_str_getdelimfd (struct str_getdelimfd *const gdfd)
 
int smtp_str_getdelimfd_set_line_and_buf (struct str_getdelimfd *const gdfd, size_t copy_len)
 
void smtp_str_getdelimfd_free (struct str_getdelimfd *const gdfd)
 
char * smtp_stpcpy (char *s1, const char *s2)
 
void * smtp_reallocarray (void *ptr, size_t nmemb, size_t size)
 
char * smtp_strdup (const char *s)
 
char * smtp_str_replace (const char *const search, const char *const replace, const char *const s)
 
size_t smtp_utf8_charlen (char c)
 
int smtp_str_has_nonascii_utf8 (const char *const s)
 
size_t smtp_strnlen_utf8 (const char *s, size_t maxlen)
 
size_t smtp_fold_whitespace_get_offset (const char *const s, unsigned int maxlen)
 
char * smtp_fold_whitespace (const char *const s, unsigned int maxlen)
 
char * smtp_chunk_split (const char *const s, size_t chunklen, const char *const end)
 
char * smtp_ffile_get_contents (FILE *stream, size_t *bytes_read)
 
char * smtp_file_get_contents (const char *const filename, size_t *bytes_read)
 
int smtp_parse_cmd_line (char *const line, struct smtp_command *const cmd)
 
int smtp_date_rfc_2822 (char *const date)
 
int smtp_address_validate_email (const char *const email)
 
int smtp_address_validate_name (const char *const name)
 
int smtp_attachment_validate_name (const char *const name)
 
int smtp_header_key_validate (const char *const key)
 
int smtp_header_value_validate (const char *const value)
 
int smtp_test_seam_dec_err_ctr (int *const test_err_ctr)
 
BIO * smtp_test_seam_bio_new_socket (int sock, int close_flag)
 
int smtp_test_seam_bio_should_retry (BIO *bio)
 
void * smtp_test_seam_calloc (size_t nelem, size_t elsize)
 
int smtp_test_seam_close (int fildes)
 
int smtp_test_seam_connect (int socket, const struct sockaddr *address, socklen_t address_len)
 
unsigned long smtp_test_seam_err_peek_error (void)
 
int smtp_test_seam_fclose (FILE *stream)
 
int smtp_test_seam_ferror (FILE *stream)
 
struct tm * smtp_test_seam_gmtime_r (const time_t *timep, struct tm *result)
 
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)
 
struct tm * smtp_test_seam_localtime_r (const time_t *timep, struct tm *result)
 
void * smtp_test_seam_malloc (size_t size)
 
time_t smtp_test_seam_mktime (struct tm *timeptr)
 
void * smtp_test_seam_realloc (void *ptr, size_t size)
 
long smtp_test_seam_recv (int socket, void *buffer, size_t length, int flags)
 
int smtp_test_seam_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
 
ssize_t smtp_test_seam_send (int socket, const void *buffer, size_t length, int flags)
 
int smtp_test_seam_socket (int domain, int type, int protocol)
 
int smtp_test_seam_ssl_connect (SSL *ssl)
 
SSL_CTX * smtp_test_seam_ssl_ctx_new (const SSL_METHOD *method)
 
int smtp_test_seam_ssl_do_handshake (SSL *ssl)
 
X509 * smtp_test_seam_ssl_get_peer_certificate (const SSL *ssl)
 
int smtp_test_seam_x509_check_host (X509 *cert, const char *name, size_t namelen, unsigned int flags, char **peername)
 
SSL * smtp_test_seam_ssl_new (SSL_CTX *ctx)
 
int smtp_test_seam_ssl_read (SSL *ssl, void *buf, int num)
 
int smtp_test_seam_ssl_write (SSL *ssl, const void *buf, int num)
 
int smtp_test_seam_sprintf (char *s, const char *format,...)
 
size_t smtp_test_seam_strlen (const char *s)
 
time_t smtp_test_seam_time (time_t *tloc)
 

Variables

int g_smtp_test_err_bio_new_socket_ctr
 
int g_smtp_test_err_bio_should_retry_ctr
 
int g_smtp_test_err_bio_should_retry_rc
 
int g_smtp_test_err_calloc_ctr
 
int g_smtp_test_err_close_ctr
 
int g_smtp_test_err_connect_ctr
 
int g_smtp_test_err_err_peek_error_ctr
 
int g_smtp_test_err_fclose_ctr
 
int g_smtp_test_err_ferror_ctr
 
int g_smtp_test_err_gmtime_r_ctr
 
int g_smtp_test_err_hmac_ctr
 
int g_smtp_test_err_localtime_r_ctr
 
int g_smtp_test_err_malloc_ctr
 
int g_smtp_test_err_mktime_ctr
 
int g_smtp_test_err_realloc_ctr
 
int g_smtp_test_err_recv_ctr
 
int g_smtp_test_err_recv_rc
 
char g_smtp_test_err_recv_bytes [90]
 
int g_smtp_test_err_select_ctr
 
int g_smtp_test_err_send_ctr
 
int g_smtp_test_send_one_byte
 
int g_smtp_test_err_si_add_size_t_ctr
 
int g_smtp_test_err_si_sub_size_t_ctr
 
int g_smtp_test_err_si_mul_size_t_ctr
 
int g_smtp_test_err_socket_ctr
 
int g_smtp_test_err_ssl_connect_ctr
 
int g_smtp_test_err_ssl_ctx_new_ctr
 
int g_smtp_test_err_ssl_do_handshake_ctr
 
int g_smtp_test_err_ssl_get_peer_certificate_ctr
 
int g_smtp_test_err_x509_check_host_ctr
 
int g_smtp_test_err_ssl_new_ctr
 
int g_smtp_test_err_ssl_read_ctr
 
int g_smtp_test_err_ssl_write_ctr
 
int g_smtp_test_err_sprintf_ctr
 
int g_smtp_test_err_sprintf_rc
 
int g_smtp_test_strlen_custom_ret
 
size_t g_smtp_test_strlen_ret_value
 
int g_smtp_test_time_custom_ret
 
time_t g_smtp_test_time_ret_value
 

Detailed Description

Test the smtp-client library.

Author
James Humphrey (mail@.nosp@m.somn.nosp@m.isoft.nosp@m..com)
Version
1.00

This smtp-client testing framework has 100% branch coverage on POSIX systems. It requires a Postfix SMTP server that supports all of the connection security and authentication methods. These functional tests also require the user to manually check and ensure that the destination addresses received all of the test emails.

This software has been placed into the public domain using CC0.

test_seams_countdown_global

The test harnesses control most of the test seams through the use of global counter values.

Setting a global counter to -1 will make the test seam function operate as it normally would. If set to a positive value, the value will continue to decrement every time the function gets called. When the counter reaches 0, the test seam will force the function to return an error value.

For example, initially setting the counter to 0 will force the test seam to return an error condition the first time it gets called. Setting the value to 1 initially will force the test seam to return an error condition on the second time it gets called.

Definition in file test.h.

Function Documentation

◆ smtp_address_validate_email()

int smtp_address_validate_email ( const char *const  email)

Validate characters in the email address.

The email address must consist only of printable characters excluding the angle brackets (<) and (>).

Parameters
[in]emailThe email address of the party.
Return values
0Successful validation.
-1Failed to validate.

Definition at line 2878 of file smtp.c.

References SMTP_LINKAGE.

Referenced by smtp_address_add(), and smtp_unit_test_all_smtp_address_validate_email().

2878  {
2879  size_t i;
2880  unsigned char uc;
2881 
2882  for(i = 0; email[i]; i++){
2883  uc = (unsigned char)email[i];
2884  if(uc <= ' ' || uc == 127 ||
2885  uc == '<' || uc == '>'){
2886  return -1;
2887  }
2888  }
2889  return 0;
2890 }
+ Here is the caller graph for this function:

◆ smtp_address_validate_name()

int smtp_address_validate_name ( const char *const  name)

Validate characters in the email name.

Email user name must consist only of printable characters, excluding the double quote character.

Parameters
[in]nameEmail name to validate.
Return values
0Successful validation.
-1Failed to validate.

Definition at line 2903 of file smtp.c.

References SMTP_LINKAGE.

Referenced by smtp_address_add(), and smtp_unit_test_all_smtp_address_validate_name().

2903  {
2904  size_t i;
2905  unsigned char uc;
2906 
2907  for(i = 0; name[i]; i++){
2908  uc = (unsigned char)name[i];
2909  if(uc < ' ' || uc == 127 || uc == '\"'){
2910  return -1;
2911  }
2912  }
2913  return 0;
2914 }
+ Here is the caller graph for this function:

◆ smtp_attachment_validate_name()

int smtp_attachment_validate_name ( const char *const  name)

Validate characters in the attachment file name.

Must consist only of printable characters or the space character ( ), and excluding the quote characters (') and (").

Parameters
[in]nameFilename of the attachment shown to recipients.
Return values
0Successful validation.
-1Failed to validate.

Definition at line 2927 of file smtp.c.

Referenced by smtp_attachment_add_mem(), and smtp_unit_test_all_smtp_attachment_validate_name().

2927  {
2928  size_t i;
2929  unsigned char uc;
2930 
2931  for(i = 0; name[i]; i++){
2932  uc = (unsigned char)name[i];
2933  if(uc < ' ' || uc == 127 ||
2934  uc == '\'' || uc == '\"'){
2935  return -1;
2936  }
2937  }
2938  return 0;
2939 }
+ Here is the caller graph for this function:

◆ smtp_base64_decode()

size_t smtp_base64_decode ( const char *const  buf,
unsigned char **  decode 
)

Decode a base64 string.

The decode parameter will get dynamically allocated by this function if it successfully completes. Therefore, the caller must free the decode parameter after use.

Parameters
[in]bufNull-terminated base64 string.
[out]decodePointer to buffer which will get dynamically allocated and will contain the decoded binary data. This parameter will get set to NULL if the memory allocation fails.
Return values
>=0Length of the data stored in the decode parameter.
-1Memory allocation failure or invalid base64 byte sequences.

Definition at line 984 of file smtp.c.

References calloc, SIZE_MAX, smtp_base64_decode_block(), SMTP_LINKAGE, smtp_si_add_size_t(), and strlen.

Referenced by smtp_auth_cram_md5(), and smtp_unit_test_base64_decode().

985  {
986  size_t buf_len;
987  size_t buf_len_inc;
988  size_t buf_i;
989  unsigned char *b64_decode;
990  size_t decode_len;
991  size_t decode_block_len;
992 
993  *decode = NULL;
994 
995  buf_len = strlen(buf);
996  if(buf_len % 4 != 0){
997  return SIZE_MAX;
998  }
999 
1000  if(smtp_si_add_size_t(buf_len, 1, &buf_len_inc) ||
1001  (b64_decode = calloc(1, buf_len_inc)) == NULL){
1002  return SIZE_MAX;
1003  }
1004 
1005  decode_len = 0;
1006  for(buf_i = 0; buf_i < buf_len; buf_i += 4){
1007  decode_block_len = smtp_base64_decode_block(
1008  (const unsigned char*)&buf[buf_i],
1009  &b64_decode[decode_len]);
1010  if(decode_block_len == 0){
1011  free(b64_decode);
1012  return SIZE_MAX;
1013  }
1014  decode_len += decode_block_len;
1015  }
1016  *decode = b64_decode;
1017  return decode_len;
1018 }
static size_t smtp_base64_decode_block(const unsigned char *const buf, unsigned char *const decode)
Definition: smtp.c:924
#define calloc
Definition: seams.h:73
#define SIZE_MAX
Definition: smtp.h:23
#define strlen
Definition: seams.h:273
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_base64_encode()

char* smtp_base64_encode ( const char *const  buf,
size_t  buflen 
)

Encode binary data into a base64 string.

Parameters
[in]bufBinary data to encode in base64.
[in]buflenNumber of bytes in the buf parameter, or -1 if null-terminated.
Return values
char*Dynamically allocated base64 encoded string. The caller must free this string when finished.
NULLMemory allocation failure.

Definition at line 825 of file smtp.c.

References calloc, SIZE_MAX, smtp_base64_encode_block(), smtp_si_mul_size_t(), and strlen.

Referenced by smtp_attachment_add_mem(), smtp_auth_cram_md5(), smtp_auth_login(), smtp_auth_plain(), and smtp_unit_test_base64_encode().

826  {
827  char *b64;
828  size_t b64_sz;
829  size_t buf_i;
830  size_t b64_i;
831  size_t remaining_block_sz;
832  size_t buf_block_sz;
833 
834  if(buflen == SIZE_MAX){
835  buflen = strlen(buf);
836  }
837 
838  /*
839  * base64 size expands by 33%
840  * +1 to round integer division up
841  * +2 for '=' padding
842  * +1 null terminator
843  */
844  if(smtp_si_mul_size_t(buflen, 4, NULL)){
845  return NULL;
846  }
847  b64_sz = (4 * buflen / 3) + 1 + 2 + 1;
848  if((b64 = calloc(1, b64_sz)) == NULL){
849  return NULL;
850  }
851 
852  if(buflen == 0){
853  return b64;
854  }
855 
856  buf_i = 0;
857  b64_i = 0;
858  remaining_block_sz = buflen;
859  while(remaining_block_sz > 0){
860  if(remaining_block_sz >= 3){
861  buf_block_sz = 3;
862  }
863  else{
864  buf_block_sz = remaining_block_sz;
865  }
866 
867  smtp_base64_encode_block(&buf[buf_i], buf_block_sz, &b64[b64_i]);
868 
869  /*
870  * Do not need to check for wrapping because these values restricted to
871  * range of b64_sz, which has already been checked for wrapping above.
872  */
873  buf_i += 3;
874  b64_i += 4;
875 
876  remaining_block_sz -= buf_block_sz;
877  }
878 
879  return b64;
880 }
#define calloc
Definition: seams.h:73
#define SIZE_MAX
Definition: smtp.h:23
static void smtp_base64_encode_block(const char *const buf, size_t buf_block_sz, char *const b64)
Definition: smtp.c:792
#define strlen
Definition: seams.h:273
SMTP_LINKAGE int smtp_si_mul_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:320
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_bin2hex()

char* smtp_bin2hex ( const unsigned char *const  s,
size_t  slen 
)

Convert binary data to lowercase hexadecimal representation.

Parameters
[in]sBuffer containing binary data to convert.
[in]slenNumber of bytes in s.
Return values
char*Dynamically allocated string consisting of a hexadecimal representation of binary data in s. The caller must free this memory when finished.
NULLMemory allocation or encoding error.

Definition at line 1031 of file smtp.c.

References malloc, SMTP_LINKAGE, smtp_si_add_size_t(), smtp_si_mul_size_t(), and sprintf.

Referenced by smtp_auth_cram_md5(), and smtp_unit_test_bin2hex().

1032  {
1033  char *snew;
1034  size_t alloc_sz;
1035  size_t i;
1036  size_t j;
1037  unsigned hex;
1038  int rc;
1039 
1040  /* alloc_sz = slen * 2 + 1 */
1041  if(smtp_si_mul_size_t(slen, 2, &alloc_sz) ||
1042  smtp_si_add_size_t(alloc_sz, 1, &alloc_sz)){
1043  return NULL;
1044  }
1045  if((snew = malloc(alloc_sz)) == NULL){
1046  return NULL;
1047  }
1048 
1049  j = 0;
1050  for(i = 0; i < slen; i++){
1051  hex = s[i];
1052  rc = sprintf(&snew[j], "%02x", hex);
1053  if(rc < 0 || (size_t)rc >= 3){
1054  free(snew);
1055  return NULL;
1056  }
1057  j += 2;
1058  }
1059  snew[j] = '\0';
1060 
1061  return snew;
1062 }
#define sprintf
Definition: seams.h:265
#define malloc
Definition: seams.h:145
SMTP_LINKAGE int smtp_si_mul_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:320
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_chunk_split()

char* smtp_chunk_split ( const char *const  s,
size_t  chunklen,
const char *const  end 
)

Splits a string into smaller chunks separated by a terminating string.

Parameters
[in]sThe string to chunk.
[in]chunklenNumber of bytes for each chunk in the string.
[in]endTerminating string placed at the end of each chunk.
Return values
char*Pointer to an allocated string with the contents split into separate chunks. The caller must free this memory when done.
NULLMemory allocation failure.

Definition at line 1312 of file smtp.c.

References calloc, SIZE_MAX, SMTP_LINKAGE, smtp_si_add_size_t(), smtp_si_mul_size_t(), smtp_strdup(), smtp_strnlen_utf8(), and strlen.

Referenced by smtp_attachment_add_mem(), and smtp_unit_test_chunk_split().

1314  {
1315  char *snew;
1316  size_t bodylen;
1317  size_t bodylen_inc;
1318  size_t endlen;
1319  size_t endlen_inc;
1320  size_t snewlen;
1321  size_t chunk_i;
1322  size_t snew_i;
1323  size_t body_i;
1324  size_t body_copy_len;
1325 
1326  if(chunklen < 1){
1327  errno = EINVAL;
1328  return NULL;
1329  }
1330 
1331  bodylen = strlen(s);
1332  endlen = strlen(end);
1333 
1334  if(bodylen < 1){
1335  return smtp_strdup(end);
1336  }
1337 
1338  /*
1339  * \0
1340  * snewlen = bodylen + (endlen + 1) * (bodylen / chunklen + 1) + 1
1341  */
1342  if(smtp_si_add_size_t(endlen, 1, &endlen_inc) ||
1343  smtp_si_add_size_t(bodylen, 1, &bodylen_inc) ||
1344  smtp_si_mul_size_t(endlen_inc, bodylen / chunklen + 1, &snewlen) ||
1345  smtp_si_add_size_t(snewlen, bodylen_inc, &snewlen) ||
1346  (snew = calloc(1, snewlen)) == NULL){
1347  return NULL;
1348  }
1349 
1350  body_i = 0;
1351  snew_i = 0;
1352  for(chunk_i = 0; chunk_i < bodylen / chunklen + 1; chunk_i++){
1353  body_copy_len = smtp_strnlen_utf8(&s[body_i], chunklen);
1354  if(body_copy_len == SIZE_MAX){
1355  free(snew);
1356  return NULL;
1357  }
1358  memcpy(&snew[snew_i], &s[body_i], body_copy_len);
1359  snew_i += body_copy_len;
1360  if(s[body_i] == '\0'){
1361  snew_i += 1;
1362  }
1363  body_i += body_copy_len;
1364 
1365  if(endlen > 0){
1366  memcpy(&snew[snew_i], end, endlen);
1367  }
1368  snew_i += endlen;
1369  }
1370 
1371  return snew;
1372 }
SMTP_LINKAGE size_t smtp_strnlen_utf8(const char *s, size_t maxlen)
Definition: smtp.c:1138
#define calloc
Definition: seams.h:73
#define SIZE_MAX
Definition: smtp.h:23
#define strlen
Definition: seams.h:273
SMTP_LINKAGE int smtp_si_mul_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:320
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
SMTP_LINKAGE char * smtp_strdup(const char *s)
Definition: smtp.c:650
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_date_rfc_2822()

int smtp_date_rfc_2822 ( char *const  date)

Convert the time into an RFC 2822 formatted string.

Example date format: Thu, 21 May 1998 05:33:29 -0700

Parameters
[out]dateBuffer that has at least SMTP_DATE_MAX_SZ bytes.
Return values
0Successfully copied the current date to the buffer.
-1Failed to establish the current date or an output format error occurred.

Definition at line 2236 of file smtp.c.

References gmtime_r, localtime_r, mktime, SMTP_DATE_MAX_SZ, sprintf, and time.

Referenced by smtp_mail(), and smtp_unit_test_date_rfc_2822().

2236  {
2237  time_t t;
2238  time_t t_local;
2239  time_t t_utc;
2240  struct tm tm_local;
2241  struct tm tm_utc;
2242  long offset_utc;
2243  double diff_local_utc;
2244  int rc;
2245 
2246  const char weekday_abbreviation[7][4] = {
2247  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
2248  };
2249 
2250  const char month_abbreviation[12][4] = {
2251  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
2252  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
2253  };
2254 
2255  if((t = time(NULL)) == (time_t)(-1)){
2256  return -1;
2257  }
2258 
2259 #ifdef SMTP_IS_WINDOWS
2260  if(localtime_s(&tm_local, &t) ||
2261  gmtime_s(&tm_utc, &t)){
2262  return -1;
2263  }
2264 #else /* POSIX */
2265  /* Not defined if system does not have localtime_r or gmtime_r. */
2266 # ifdef SMTP_TIME_NO_REENTRANT
2267  struct tm *tm;
2268 
2269  /* localtime() not thread-safe. */
2270  if((tm = localtime(&t)) == NULL){
2271  return -1;
2272  }
2273  memcpy(&tm_local, tm, sizeof(tm_local));
2274 
2275  /* gmtime() not thread-safe. */
2276  if((tm = gmtime(&t)) == NULL){
2277  return -1;
2278  }
2279  memcpy(&tm_utc, tm, sizeof(tm_utc));
2280 # else /* Reentrant versions: localtime_r() and gmtime_r(). */
2281  if(localtime_r(&t, &tm_local) == NULL ||
2282  gmtime_r(&t, &tm_utc) == NULL){
2283  return -1;
2284  }
2285 # endif /* SMTP_TIME_NO_REENTRANT */
2286 #endif /* SMTP_IS_WINDOWS */
2287 
2288  if((t_local = mktime(&tm_local)) == (time_t)(-1)){
2289  return -1;
2290  }
2291 
2292  if((t_utc = mktime(&tm_utc)) == (time_t)(-1)){
2293  return -1;
2294  }
2295 
2296  /*
2297  * After computing the offset, it will contain a maximum of 4 digits.
2298  * For example, PST time zone will have an offset of -800 which will get
2299  * formatted as -0800 in the sprintf call below.
2300  */
2301  diff_local_utc = difftime(t_local, t_utc);
2302  offset_utc = (long)diff_local_utc;
2303  offset_utc = offset_utc / 60 / 60 * 100;
2304 
2305  rc = sprintf(date,
2306  "%s, %02d %s %d %02d:%02d:%02d %0+5ld",
2307  weekday_abbreviation[tm_local.tm_wday],
2308  tm_local.tm_mday,
2309  month_abbreviation[tm_local.tm_mon],
2310  tm_local.tm_year + 1900,
2311  tm_local.tm_hour,
2312  tm_local.tm_min,
2313  tm_local.tm_sec, /* 0 - 60 (leap second) */
2314  offset_utc);
2315 
2316  if(rc + 1 != SMTP_DATE_MAX_SZ - 15){ /* See @ref SMTP_DATE_MAX_SZ for -5. */
2317  return -1;
2318  }
2319 
2320  return 0;
2321 }
#define time
Definition: seams.h:281
#define sprintf
Definition: seams.h:265
#define gmtime_r
Definition: seams.h:121
#define mktime
Definition: seams.h:153
#define localtime_r
Definition: seams.h:137
#define SMTP_DATE_MAX_SZ
Definition: smtp.c:2222
+ Here is the caller graph for this function:

◆ smtp_ffile_get_contents()

char* smtp_ffile_get_contents ( FILE *  stream,
size_t *  bytes_read 
)

Read the entire contents of a file stream and store the data into a dynamically allocated buffer.

Parameters
[in]streamFile stream already opened by the caller.
[out]bytes_readNumber of bytes stored in the return buffer.
Return values
char*A dynamically allocated buffer which contains the entire contents of stream. The caller must free this memory when done.
NULLMemory allocation or file read error.

Definition at line 1386 of file smtp.c.

References ferror, realloc, SMTP_LINKAGE, and smtp_si_add_size_t().

Referenced by smtp_attachment_add_fp(), and smtp_file_get_contents().

1387  {
1388  char *read_buf;
1389  size_t bufsz;
1390  size_t bufsz_inc;
1391  char *new_buf;
1392  size_t bytes_read_loop;
1393  const size_t BUFSZ_INCREMENT = 512;
1394 
1395  read_buf = NULL;
1396  bufsz = 0;
1397 
1398  if(bytes_read){
1399  *bytes_read = 0;
1400  }
1401 
1402  do{
1403  if(smtp_si_add_size_t(bufsz, BUFSZ_INCREMENT, &bufsz_inc) ||
1404  (new_buf = realloc(read_buf, bufsz_inc)) == NULL){
1405  free(read_buf);
1406  return NULL;
1407  }
1408  read_buf = new_buf;
1409  bufsz = bufsz_inc;
1410 
1411  bytes_read_loop = fread(&read_buf[bufsz - BUFSZ_INCREMENT],
1412  sizeof(char),
1413  BUFSZ_INCREMENT,
1414  stream);
1415  if(bytes_read){
1416  *bytes_read += bytes_read_loop;
1417  }
1418  if(ferror(stream)){
1419  free(read_buf);
1420  return NULL;
1421  }
1422  } while(!feof(stream));
1423 
1424  return read_buf;
1425 }
#define ferror
Definition: seams.h:113
#define realloc
Definition: seams.h:161
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_file_get_contents()

char* smtp_file_get_contents ( const char *const  filename,
size_t *  bytes_read 
)

Read the entire contents of a file from a given path, and store the data into a dynamically allocated buffer.

Parameters
[in]filenamePath of file to open and read from.
[out]bytes_readNumber of bytes stored in the return buffer.
Return values
char*A dynamically allocated buffer which has the contents of the file at filename. The caller must free this memory when done.
NULLMemory allocation or file read error.

Definition at line 1439 of file smtp.c.

References fclose, smtp_ffile_get_contents(), and SMTP_LINKAGE.

Referenced by smtp_attachment_add_path(), smtp_test_config_load_from_file(), smtp_unit_test_all_file_get_contents(), and smtp_unit_test_file_get_contents().

1440  {
1441  FILE *fp;
1442  char *read_buf;
1443 
1444  if((fp = fopen(filename, "rb")) == NULL){
1445  return NULL;
1446  }
1447 
1448  read_buf = smtp_ffile_get_contents(fp, bytes_read);
1449 
1450  if(fclose(fp) == EOF){
1451  free(read_buf);
1452  read_buf = NULL;
1453  }
1454 
1455  return read_buf;
1456 }
SMTP_LINKAGE char * smtp_ffile_get_contents(FILE *stream, size_t *bytes_read)
Definition: smtp.c:1386
#define fclose
Definition: seams.h:105
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_fold_whitespace()

char* smtp_fold_whitespace ( const char *const  s,
unsigned int  maxlen 
)

Fold a line at whitespace characters.

This function tries to keep the total number of characters per line under maxlen, but does not guarantee this. For really long text with no whitespace, the line will still extend beyond maxlen and possibly beyond the RFC limit as defined in SMTP_LINE_MAX. This is by design and intended to keep the algorithm simpler to implement. Users sending long headers with no space characters should not assume that will work, but modern email systems may correctly process those headers anyways.

Lines get folded by adding a [CR][LF] and then two space characters on the beginning of the next line. For example, this Subject line:

Subject: Email[WS][WS]Header

Would get folded like this (assuming a small maxlen):

Subject: Email[WS][CR][LF] [WS][WS]Header

Parameters
[in]sString to fold.
[in]maxlenNumber of bytes for each line in the string (soft limit). The minimum value of this parameter is 3 and it will get forced to 3 if the provided value is less.
Return values
char*Pointer to an allocated string with the contents split into separate lines. The caller must free this memory when done.
NULLMemory allocation failed.

Definition at line 1250 of file smtp.c.

References realloc, smtp_fold_whitespace_get_offset(), SMTP_LINKAGE, smtp_si_add_size_t(), and strlen.

Referenced by smtp_print_header(), and smtp_unit_test_fold_whitespace().

1251  {
1252  const char *const SMTP_LINE_FOLD_STR = "\r\n ";
1253  size_t end_slen;
1254  size_t s_i;
1255  size_t buf_i;
1256  size_t bufsz;
1257  size_t ws_offset;
1258  char *buf;
1259  char *buf_new;
1260 
1261  if(maxlen < 3){
1262  maxlen = 3;
1263  }
1264 
1265  end_slen = strlen(SMTP_LINE_FOLD_STR);
1266 
1267  s_i = 0;
1268  buf_i = 0;
1269  bufsz = 0;
1270  buf = NULL;
1271 
1272  while(1){
1273  ws_offset = smtp_fold_whitespace_get_offset(&s[s_i], maxlen - 2);
1274 
1275  /* bufsz += ws_offset + end_slen + 1 */
1276  if(smtp_si_add_size_t(bufsz, ws_offset, &bufsz) ||
1277  smtp_si_add_size_t(bufsz, end_slen, &bufsz) ||
1278  smtp_si_add_size_t(bufsz, 1, &bufsz) ||
1279  (buf_new = realloc(buf, bufsz)) == NULL){
1280  free(buf);
1281  return NULL;
1282  }
1283  buf = buf_new;
1284  memcpy(&buf[buf_i], &s[s_i], ws_offset);
1285  buf[buf_i + ws_offset] = '\0';
1286 
1287  if(s[s_i + ws_offset] == '\0'){
1288  break;
1289  }
1290 
1291  buf_i += ws_offset;
1292  strcat(&buf[buf_i], SMTP_LINE_FOLD_STR);
1293  buf_i += end_slen;
1294 
1295  /* WS */
1296  s_i += ws_offset + 1;
1297  }
1298  return buf;
1299 }
#define realloc
Definition: seams.h:161
SMTP_LINKAGE size_t smtp_fold_whitespace_get_offset(const char *const s, unsigned int maxlen)
Definition: smtp.c:1179
#define strlen
Definition: seams.h:273
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_fold_whitespace_get_offset()

size_t smtp_fold_whitespace_get_offset ( const char *const  s,
unsigned int  maxlen 
)

Get the offset of the next whitespace block to process folding.

If a string does not have whitespace before maxlen, then the index will get returned past maxlen. Also returns the index of NULL character if that fits within the next block. The caller must check for the NULL index to indicate the last block. It will skip past any leading whitespace even if that means going over maxlen.

Examples: smtp_fold_whitespace_get_offset ("Subject: Test WS", 1/2/8/9/10/13) -> 8 smtp_fold_whitespace_get_offset ("Subject: Test WS", 14/15) -> 13 smtp_fold_whitespace_get_offset ("Subject: Test WS", 17/18) -> 16

Parameters
[in]sString to get offset from.
[in]maxlenNumber of bytes for each line in the string (soft limit).
Returns
Index in s.

Definition at line 1179 of file smtp.c.

Referenced by smtp_fold_whitespace(), and smtp_unit_test_fold_whitespace_get_offset().

1180  {
1181  size_t i;
1182  size_t offset_i;
1183 
1184  i = 0;
1185  offset_i = 0;
1186 
1187  while(s[i] == ' ' || s[i] == '\t'){
1188  i += 1;
1189  }
1190 
1191  while(s[i]){
1192  if(s[i] == ' ' || s[i] == '\t'){
1193  do{
1194  i += 1;
1195  } while(s[i] == ' ' || s[i] == '\t');
1196  i -= 1;
1197  if(i < maxlen || !offset_i){
1198  offset_i = i;
1199  }
1200  else{
1201  break;
1202  }
1203  }
1204  i += 1;
1205  }
1206 
1207  if(!offset_i || i < maxlen){
1208  offset_i = i;
1209  }
1210 
1211  return offset_i;
1212 }
+ Here is the caller graph for this function:

◆ smtp_header_key_validate()

int smtp_header_key_validate ( const char *const  key)

Validate characters in the email header key.

Must consist only of printable US-ASCII characters except colon.

Parameters
[in]keyHeader key to validate.
Return values
0Successful validation.
-1Failed to validate.

Definition at line 2822 of file smtp.c.

References SMTP_LINKAGE, and strlen.

Referenced by smtp_header_add(), and smtp_unit_test_all_smtp_header_key_validate().

2822  {
2823  unsigned char uc;
2824  size_t i;
2825  size_t keylen;
2826 
2827  keylen = strlen(key);
2828  if(keylen < 1){
2829  return -1;
2830  }
2831 
2832  for(i = 0; i < keylen; i++){
2833  uc = (unsigned char)key[i];
2834  if(uc <= ' ' || uc > 126 || uc == ':'){
2835  return -1;
2836  }
2837  }
2838 
2839  return 0;
2840 }
#define strlen
Definition: seams.h:273
+ Here is the caller graph for this function:

◆ smtp_header_value_validate()

int smtp_header_value_validate ( const char *const  value)

Validate characters in the email header contents.

Must consist only of printable character, space, or horizontal tab.

Parameters
[in]valueHeader value to validate.
Return values
0Successful validation.
-1Failed to validate.

Definition at line 2852 of file smtp.c.

References SMTP_LINKAGE.

Referenced by smtp_header_add(), and smtp_unit_test_all_smtp_header_value_validate().

2852  {
2853  size_t i;
2854  unsigned char uc;
2855 
2856  for(i = 0; value[i]; i++){
2857  uc = (unsigned char)value[i];
2858  if((uc < ' ' || uc > 126) &&
2859  uc != '\t' &&
2860  uc < 0x80){ /* Allow UTF-8 byte sequence. */
2861  return -1;
2862  }
2863  }
2864  return 0;
2865 }
+ Here is the caller graph for this function:

◆ smtp_parse_cmd_line()

int smtp_parse_cmd_line ( char *const  line,
struct smtp_command *const  cmd 
)

Parse a server response line into the smtp_command data structure.

Parameters
[in]lineServer response string.
[out]cmdStructure containing the server response data broken up into its separate components.
Returns
See smtp_result_code.

Definition at line 1467 of file smtp.c.

References smtp_command::code, smtp_command::more, SMTP_BEGIN_MAIL, SMTP_INTERNAL_ERROR, strlen, and smtp_command::text.

Referenced by smtp_auth_cram_md5(), smtp_read_and_parse_code(), and smtp_unit_test_parse_cmd_line().

1468  {
1469  char *ep;
1470  char code_str[4];
1471  size_t line_len;
1472  unsigned long int ulcode;
1473 
1474  line_len = strlen(line);
1475  if(line_len < 5){
1476  cmd->code = SMTP_INTERNAL_ERROR;
1477  cmd->more = 0;
1478  cmd->text = line;
1479  return cmd->code;
1480  }
1481 
1482  cmd->text = &line[4];
1483 
1484  memcpy(code_str, line, 3);
1485  code_str[3] = '\0';
1486  ulcode = strtoul(code_str, &ep, 10);
1487  if(*ep != '\0' || ulcode > SMTP_BEGIN_MAIL){
1488  cmd->code = SMTP_INTERNAL_ERROR;
1489  }
1490  else{
1491  cmd->code = (enum smtp_result_code)ulcode;
1492  }
1493 
1494  if(line[3] == '-'){
1495  cmd->more = 1;
1496  }
1497  else{
1498  cmd->more = 0;
1499  }
1500  return cmd->code;
1501 }
enum smtp_result_code code
Definition: smtp.h:531
int more
Definition: smtp.h:539
smtp_result_code
Definition: smtp.h:483
#define strlen
Definition: seams.h:273
const char * text
Definition: smtp.h:544
+ Here is the caller graph for this function:

◆ smtp_reallocarray()

void* smtp_reallocarray ( void *  ptr,
size_t  nmemb,
size_t  size 
)

Reallocate memory with unsigned wrapping checks.

Parameters
[in]ptrExisting allocation buffer, or NULL when allocating a new buffer.
[in]nmembNumber of elements to allocate.
[in]sizeSize of each element in nmemb.
Return values
void*Pointer to a reallocated buffer containing nmemb * size bytes.
NULLFailed to reallocate memory.

Definition at line 622 of file smtp.c.

References realloc, SMTP_LINKAGE, and smtp_si_mul_size_t().

Referenced by smtp_address_add(), smtp_attachment_add_mem(), smtp_header_add(), and smtp_unit_test_reallocarray().

624  {
625  void *alloc;
626  size_t size_mul;
627 
628  if(smtp_si_mul_size_t(nmemb, size, &size_mul)){
629  alloc = NULL;
630  errno = ENOMEM;
631  }
632  else{
633  alloc = realloc(ptr, size_mul);
634  }
635  return alloc;
636 }
#define realloc
Definition: seams.h:161
SMTP_LINKAGE int smtp_si_mul_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:320
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_si_add_size_t()

int smtp_si_add_size_t ( const size_t  a,
const size_t  b,
size_t *const  result 
)

Check if adding a size_t value will cause a wrap.

Parameters
[in]aAdd this value with b.
[in]bAdd this value with a.
[out]resultSave the addition to this buffer. Does not perform the addition if set to NULL.
Return values
1Value wrapped.
0Value did not wrap.

Definition at line 252 of file smtp.c.

References g_smtp_test_err_si_add_size_t_ctr, SIZE_MAX, SMTP_LINKAGE, and smtp_test_seam_dec_err_ctr().

Referenced by smtp_address_add(), smtp_append_address_to_header(), smtp_attachment_add_mem(), smtp_auth_cram_md5(), smtp_auth_login(), smtp_auth_plain(), smtp_base64_decode(), smtp_bin2hex(), smtp_chunk_split(), smtp_ffile_get_contents(), smtp_fold_whitespace(), smtp_header_add(), smtp_mail_envelope_header(), smtp_print_header(), smtp_print_mime_attachment(), smtp_print_mime_header_and_body(), smtp_puts_terminate(), smtp_str_getdelimfd(), smtp_str_getdelimfd_set_line_and_buf(), smtp_str_replace(), smtp_strdup(), and smtp_unit_test_all_si().

254  {
255  int wraps;
256 
257 #ifdef SMTP_TEST
259  return 1;
260  }
261 #endif /* SMTP_TEST */
262 
263  if(SIZE_MAX - a < b){
264  wraps = 1;
265  }
266  else{
267  wraps = 0;
268  }
269  if(result){
270  *result = a + b;
271  }
272  return wraps;
273 }
#define SIZE_MAX
Definition: smtp.h:23
int g_smtp_test_err_si_add_size_t_ctr
Definition: seams.c:137
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_si_mul_size_t()

int smtp_si_mul_size_t ( const size_t  a,
const size_t  b,
size_t *const  result 
)

Check if multiplying a size_t value will cause a wrap.

Parameters
[in]aMultiply this value with b.
[in]bMultiply this value with a.
[out]resultSave the multiplication to this buffer. Does not perform the multiplication if set to NULL.
Return values
1Value wrapped.
0Value did not wrap.

Definition at line 320 of file smtp.c.

References g_smtp_test_err_si_mul_size_t_ctr, SIZE_MAX, and smtp_test_seam_dec_err_ctr().

Referenced by smtp_base64_encode(), smtp_bin2hex(), smtp_chunk_split(), smtp_reallocarray(), and smtp_unit_test_all_si().

322  {
323  int wraps;
324 
325 #ifdef SMTP_TEST
327  return 1;
328  }
329 #endif /* SMTP_TEST */
330 
331  if(b != 0 && a > SIZE_MAX / b){
332  wraps = 1;
333  }
334  else{
335  wraps = 0;
336  }
337  if(result){
338  *result = a * b;
339  }
340  return wraps;
341 }
#define SIZE_MAX
Definition: smtp.h:23
int g_smtp_test_err_si_mul_size_t_ctr
Definition: seams.c:149
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_si_sub_size_t()

int smtp_si_sub_size_t ( const size_t  a,
const size_t  b,
size_t *const  result 
)

Check if subtracting a size_t value will cause wrap.

Parameters
[in]aSubtract this value by b.
[in]bSubtract this value from a.
[out]resultSave the subtraction to this buffer. Does not perform the subtraction if set to NULL.
Return values
1Value wrapped.
0Value did not wrap.

Definition at line 286 of file smtp.c.

References g_smtp_test_err_si_sub_size_t_ctr, SMTP_LINKAGE, and smtp_test_seam_dec_err_ctr().

Referenced by smtp_str_getdelimfd(), smtp_str_getdelimfd_set_line_and_buf(), and smtp_unit_test_all_si().

288  {
289  int wraps;
290 
291 #ifdef SMTP_TEST
293  return 1;
294  }
295 #endif /* SMTP_TEST */
296 
297  if(a < b){
298  wraps = 1;
299  }
300  else{
301  wraps = 0;
302  }
303  if(result){
304  *result = a - b;
305  }
306  return wraps;
307 }
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_stpcpy()

char* smtp_stpcpy ( char *  s1,
const char *  s2 
)

Copy a string and get the pointer to the end of the copied buffer.

This function behaves similar to POSIX stpcpy(), useful for concatenating multiple strings onto a buffer. It always adds a null-terminated byte at the end of the string.

Parameters
[in]s1Destination buffer.
[in]s2Null-terminated source string to copy to s1.
Returns
Pointer to location in s1 after the last copied byte.

Definition at line 599 of file smtp.c.

References SMTP_LINKAGE.

Referenced by smtp_append_address_to_header(), smtp_auth_cram_md5(), smtp_auth_login(), smtp_auth_plain(), smtp_mail_envelope_header(), smtp_print_header(), smtp_print_mime_attachment(), smtp_print_mime_end(), smtp_print_mime_header_and_body(), smtp_puts_terminate(), and smtp_unit_test_stpcpy().

600  {
601  size_t i;
602 
603  i = 0;
604  do{
605  s1[i] = s2[i];
606  } while(s2[i++] != '\0');
607  return &s1[i-1];
608 }
+ Here is the caller graph for this function:

◆ smtp_str_getdelimfd()

int smtp_str_getdelimfd ( struct str_getdelimfd *const  gdfd)

Read and parse a delimited string using a custom socket read function.

This interface handles all of the logic for expanding the buffer, parsing the delimiter in the buffer, and returning each "line" to the caller for handling.

Parameters
[in]gdfdSee str_getdelimfd.
Returns
See str_getdelim_retcode.

Definition at line 523 of file smtp.c.

References str_getdelimfd::_buf, str_getdelimfd::_buf_len, str_getdelimfd::_bufsz, str_getdelimfd::delim, str_getdelimfd::getdelimfd_read, realloc, SMTP_GETDELIM_READ_SZ, SMTP_LINKAGE, smtp_si_add_size_t(), smtp_si_sub_size_t(), smtp_str_getdelimfd_search_delim(), smtp_str_getdelimfd_set_line_and_buf(), smtp_str_getdelimfd_throw_error(), STRING_GETDELIMFD_DONE, STRING_GETDELIMFD_ERROR, and STRING_GETDELIMFD_NEXT.

Referenced by smtp_getline(), and smtp_unit_test_str_getdelimfd().

523  {
524  size_t delim_pos;
525  long bytes_read;
526  void *read_buf_ptr;
527  char *buf_new;
528  size_t buf_sz_remaining;
529  size_t buf_sz_new;
530 
531  if(gdfd->getdelimfd_read == NULL){
533  }
534 
535  bytes_read = -1;
536 
537  while(1){
539  gdfd->_buf_len,
540  gdfd->delim,
541  &delim_pos)){
542  if(smtp_str_getdelimfd_set_line_and_buf(gdfd, delim_pos) < 0){
543  return smtp_str_getdelimfd_throw_error(gdfd);
544  }
545  return STRING_GETDELIMFD_NEXT;
546  }else if(bytes_read == 0){
547  if(smtp_str_getdelimfd_set_line_and_buf(gdfd, gdfd->_buf_len) < 0){
548  return smtp_str_getdelimfd_throw_error(gdfd);
549  }
550  return STRING_GETDELIMFD_DONE;
551  }
552 
553  if(smtp_si_sub_size_t(gdfd->_bufsz, gdfd->_buf_len, &buf_sz_remaining)){
554  return smtp_str_getdelimfd_throw_error(gdfd);
555  }
556 
557  if(buf_sz_remaining < SMTP_GETDELIM_READ_SZ){
558  if(smtp_si_add_size_t(buf_sz_remaining,
560  &buf_sz_new)){
561  return smtp_str_getdelimfd_throw_error(gdfd);
562  }
563  buf_new = realloc(gdfd->_buf, buf_sz_new);
564  if(buf_new == NULL){
565  return smtp_str_getdelimfd_throw_error(gdfd);
566  }
567  gdfd->_buf = buf_new;
568  gdfd->_bufsz = buf_sz_new;
569  }
570 
571  if(smtp_si_add_size_t((size_t)gdfd->_buf, gdfd->_buf_len, NULL)){
572  return smtp_str_getdelimfd_throw_error(gdfd);
573  }
574  read_buf_ptr = gdfd->_buf + gdfd->_buf_len;
575  bytes_read = (*gdfd->getdelimfd_read)(gdfd,
576  read_buf_ptr,
578  if(bytes_read < 0 ||
580  (size_t)bytes_read,
581  &gdfd->_buf_len)){
582  return smtp_str_getdelimfd_throw_error(gdfd);
583  }
584  }
585 }
#define SMTP_GETDELIM_READ_SZ
Definition: smtp.c:88
#define realloc
Definition: seams.h:161
size_t _buf_len
Definition: smtp.h:587
static int smtp_str_getdelimfd_search_delim(const char *const buf, size_t buf_len, int delim, size_t *const delim_pos)
Definition: smtp.c:431
char * _buf
Definition: smtp.h:577
SMTP_LINKAGE int smtp_si_sub_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:286
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
SMTP_LINKAGE int smtp_str_getdelimfd_set_line_and_buf(struct str_getdelimfd *const gdfd, size_t copy_len)
Definition: smtp.c:457
int delim
Definition: smtp.h:620
static enum str_getdelim_retcode smtp_str_getdelimfd_throw_error(struct str_getdelimfd *const gdfd)
Definition: smtp.c:507
long(* getdelimfd_read)(struct str_getdelimfd *const gdfd, void *buf, size_t count)
Definition: smtp.h:608
size_t _bufsz
Definition: smtp.h:582
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_str_getdelimfd_free()

void smtp_str_getdelimfd_free ( struct str_getdelimfd *const  gdfd)

Free memory in the str_getdelimfd data structure.

Parameters
[in]gdfdFrees memory stored in this socket parsing structure.

Definition at line 489 of file smtp.c.

References str_getdelimfd::_buf, str_getdelimfd::_buf_len, str_getdelimfd::_bufsz, str_getdelimfd::line, and str_getdelimfd::line_len.

Referenced by smtp_close(), smtp_str_getdelimfd_throw_error(), and smtp_unit_test_str_getdelimfd().

489  {
490  free(gdfd->_buf);
491  free(gdfd->line);
492  gdfd->_buf = NULL;
493  gdfd->_bufsz = 0;
494  gdfd->_buf_len = 0;
495  gdfd->line = NULL;
496  gdfd->line_len = 0;
497 }
size_t _buf_len
Definition: smtp.h:587
size_t line_len
Definition: smtp.h:597
char * line
Definition: smtp.h:592
char * _buf
Definition: smtp.h:577
size_t _bufsz
Definition: smtp.h:582
+ Here is the caller graph for this function:

◆ smtp_str_getdelimfd_set_line_and_buf()

int smtp_str_getdelimfd_set_line_and_buf ( struct str_getdelimfd *const  gdfd,
size_t  copy_len 
)

Set the internal line buffer to the number of bytes specified.

Parameters
[in]gdfdSee str_getdelimfd.
[in]copy_lenNumber of bytes to copy to the internal line buffer.
Return values
0Successfully allocated and copied data over to the new line buffer.
-1Failed to allocate memory for the new line buffer.

Definition at line 457 of file smtp.c.

References str_getdelimfd::_buf, str_getdelimfd::_buf_len, calloc, str_getdelimfd::line, str_getdelimfd::line_len, SMTP_LINKAGE, smtp_si_add_size_t(), and smtp_si_sub_size_t().

Referenced by smtp_str_getdelimfd(), and smtp_unit_test_getdelimfd_set_line_and_buf().

458  {
459  size_t copy_len_inc;
460  size_t nbytes_to_shift;
461  size_t new_buf_len;
462 
463  if(gdfd->line){
464  free(gdfd->line);
465  gdfd->line = NULL;
466  }
467 
468  if(smtp_si_add_size_t(copy_len, 1, &copy_len_inc) ||
469  smtp_si_add_size_t((size_t)gdfd->_buf, copy_len_inc, NULL) ||
470  smtp_si_sub_size_t(gdfd->_buf_len, copy_len, &nbytes_to_shift) ||
471  (gdfd->line = calloc(1, copy_len_inc)) == NULL){
472  return -1;
473  }
474  memcpy(gdfd->line, gdfd->_buf, copy_len);
475  gdfd->line_len = copy_len;
476  memmove(gdfd->_buf, gdfd->_buf + copy_len_inc, nbytes_to_shift);
477  if(smtp_si_sub_size_t(nbytes_to_shift, 1, &new_buf_len) == 0){
478  gdfd->_buf_len = new_buf_len;
479  }
480  return 0;
481 }
#define calloc
Definition: seams.h:73
size_t _buf_len
Definition: smtp.h:587
size_t line_len
Definition: smtp.h:597
char * line
Definition: smtp.h:592
char * _buf
Definition: smtp.h:577
SMTP_LINKAGE int smtp_si_sub_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:286
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_str_has_nonascii_utf8()

int smtp_str_has_nonascii_utf8 ( const char *const  s)

Check if a string contains non-ASCII UTF-8 characters.

Uses the simple algorithm from smtp_utf8_charlen to check for non-ASCII UTF-8 characters.

Parameters
[in]sUTF-8 string.
Return values
1String contains non-ASCII UTF-8 characters.
0String contains only ASCII characters.

Definition at line 1110 of file smtp.c.

References SMTP_LINKAGE, and smtp_utf8_charlen().

Referenced by smtp_mail_envelope_header(), and smtp_unit_test_all_smtp_str_has_nonascii_utf8().

1110  {
1111  size_t i;
1112  size_t charlen;
1113 
1114  for(i = 0; s[i]; i++){
1115  charlen = smtp_utf8_charlen(s[i]);
1116  if(charlen != 1){
1117  return 1;
1118  }
1119  }
1120  return 0;
1121 }
SMTP_LINKAGE size_t smtp_utf8_charlen(char c)
Definition: smtp.c:1078
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_str_replace()

char* smtp_str_replace ( const char *const  search,
const char *const  replace,
const char *const  s 
)

Search for all substrings in a string and replace each instance with a replacement string.

Parameters
[in]searchSubstring to search for in s.
[in]replaceReplace each instance of the search string with this.
[in]sNull-terminated string to search and replace.
Return values
char*A dynamically allocated string with the replaced instances as described above. The caller must free the allocated memory when finished.
NULLMemory allocation failure.

Definition at line 679 of file smtp.c.

References realloc, smtp_si_add_size_t(), smtp_strdup(), and strlen.

Referenced by smtp_print_email(), and smtp_unit_test_str_replace().

681  {
682  size_t search_len;
683  size_t replace_len;
684  size_t replace_len_inc;
685  size_t slen;
686  size_t slen_inc;
687  size_t s_idx;
688  size_t snew_len;
689  size_t snew_len_inc;
690  size_t snew_sz;
691  size_t snew_sz_dup;
692  size_t snew_sz_plus_slen;
693  size_t snew_replace_len_inc;
694  char *snew;
695  char *stmp;
696 
697  search_len = strlen(search);
698  replace_len = strlen(replace);
699  slen = strlen(s);
700  s_idx = 0;
701  snew = NULL;
702  snew_len = 0;
703  snew_sz = 0;
704 
705  if(smtp_si_add_size_t(replace_len, 1, &replace_len_inc) ||
706  smtp_si_add_size_t(slen, 1, &slen_inc)){
707  return NULL;
708  }
709 
710  if(s[0] == '\0'){
711  return smtp_strdup("");
712  }
713  else if(search_len < 1){
714  return smtp_strdup(s);
715  }
716 
717  while(s[s_idx]){
718  if(smtp_si_add_size_t(snew_len, 1, &snew_len_inc) ||
719  smtp_si_add_size_t(snew_sz, snew_sz, &snew_sz_dup) ||
720  smtp_si_add_size_t(snew_sz, slen, &snew_sz_plus_slen)){
721  free(snew);
722  return NULL;
723  }
724 
725  if(strncmp(&s[s_idx], search, search_len) == 0){
726  if(smtp_si_add_size_t(snew_len, replace_len_inc, &snew_replace_len_inc)){
727  free(snew);
728  return NULL;
729  }
730  if(snew_replace_len_inc >= snew_sz){
731  /* snew_sz += snew_sz + slen + replace_len + 1 */
732  if(smtp_si_add_size_t(snew_sz_dup, slen_inc, &snew_sz) ||
733  smtp_si_add_size_t(snew_sz, replace_len, &snew_sz) ||
734  (stmp = realloc(snew, snew_sz)) == NULL){
735  free(snew);
736  return NULL;
737  }
738  snew = stmp;
739  }
740  memcpy(&snew[snew_len], replace, replace_len);
741  snew_len += replace_len;
742  s_idx += search_len;
743  }
744  else{
745  if(snew_len_inc >= snew_sz){
746  /* snew_sz += snew_sz + slen + snew_len + 1 */
747  if(smtp_si_add_size_t(snew_sz_dup, slen, &snew_sz) ||
748  smtp_si_add_size_t(snew_sz, snew_len_inc, &snew_sz) ||
749  (stmp = realloc(snew, snew_sz)) == NULL){
750  free(snew);
751  return NULL;
752  }
753  snew = stmp;
754  }
755  snew[snew_len] = s[s_idx];
756  s_idx += 1;
757  snew_len = snew_len_inc;
758  }
759  }
760  snew[snew_len] = '\0';
761 
762  return snew;
763 }
#define realloc
Definition: seams.h:161
#define strlen
Definition: seams.h:273
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
SMTP_LINKAGE char * smtp_strdup(const char *s)
Definition: smtp.c:650
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_strdup()

char* smtp_strdup ( const char *  s)

Copy a string into a new dynamically allocated buffer.

Returns a dynamically allocated string, with the same contents as the input string. The caller must free the returned string when finished.

Parameters
[in]sString to duplicate.
Return values
char*Pointer to a new dynamically allocated string duplicated from s.
NULLFailed to allocate memory for the new duplicate string.

Definition at line 650 of file smtp.c.

References malloc, SMTP_LINKAGE, smtp_si_add_size_t(), and strlen.

Referenced by smtp_address_add(), smtp_attachment_add_mem(), smtp_chunk_split(), smtp_header_add(), smtp_puts_dbg(), smtp_str_repeat(), smtp_str_replace(), smtp_unit_test_parse_cmd_line(), and smtp_unit_test_strdup().

650  {
651  char *dup;
652  size_t dup_len;
653  size_t slen;
654 
655  slen = strlen(s);
656  if(smtp_si_add_size_t(slen, 1, &dup_len)){
657  dup = NULL;
658  errno = ENOMEM;
659  }
660  else if((dup = malloc(dup_len)) != NULL){
661  memcpy(dup, s, dup_len);
662  }
663  return dup;
664 }
#define malloc
Definition: seams.h:145
#define strlen
Definition: seams.h:273
SMTP_LINKAGE int smtp_si_add_size_t(const size_t a, const size_t b, size_t *const result)
Definition: smtp.c:252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_strnlen_utf8()

size_t smtp_strnlen_utf8 ( const char *  s,
size_t  maxlen 
)

Get the number of bytes in a UTF-8 string, or a shorter count if the string exceeds a maximum specified length.

See maxlen for more information on multi-byte parsing.

Parameters
[in]sNull-terminated UTF-8 string.
[in]maxlenDo not check more than maxlen bytes of string s except if in the middle of a multi-byte character.
Return values
strlen(s)If length of s has less bytes than maxlen or the same number of bytes as maxlen. See maxlen for more details.
maxlenIf length of s has more bytes than maxlen.
-1If s contains an invalid UTF-8 byte sequence.

Definition at line 1138 of file smtp.c.

References SIZE_MAX, SMTP_LINKAGE, and smtp_utf8_charlen().

Referenced by smtp_chunk_split(), and smtp_unit_test_strnlen_utf8().

1139  {
1140  size_t i;
1141  size_t utf8_i;
1142  size_t utf8_len;
1143 
1144  for(i = 0; *s && i < maxlen; i += utf8_len){
1145  utf8_len = smtp_utf8_charlen(*s);
1146  if(utf8_len == 0){
1147  return SIZE_MAX;
1148  }
1149 
1150  for(utf8_i = 0; utf8_i < utf8_len; utf8_i++){
1151  if(!*s){
1152  return SIZE_MAX;
1153  }
1154  s += 1;
1155  }
1156  }
1157  return i;
1158 }
#define SIZE_MAX
Definition: smtp.h:23
SMTP_LINKAGE size_t smtp_utf8_charlen(char c)
Definition: smtp.c:1078
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtp_test_seam_bio_new_socket()

BIO* smtp_test_seam_bio_new_socket ( int  sock,
int  close_flag 
)

Allows the test harness to control when BIO_new_socket() fails.

Parameters
[in]sockExisting socket to attach the BIO to.
[in]close_flagClose flag for new BIO.
Return values
BIO*New BIO created on existing socket.
NULLFailed to create the new BIO.

Definition at line 263 of file seams.c.

References BIO_new_socket, g_smtp_test_err_bio_new_socket_ctr, and smtp_test_seam_dec_err_ctr().

264  {
266  return NULL;
267  }
268  return BIO_new_socket(sock, close_flag);
269 }
int g_smtp_test_err_bio_new_socket_ctr
Definition: seams.c:28
#define BIO_new_socket
Definition: seams.h:57
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_bio_should_retry()

int smtp_test_seam_bio_should_retry ( BIO *  bio)

Allows the test harness to control when BIO_should_retry() fails.

Parameters
[in]bioExisting BIO connection.
Return values
0The error condition does not allow a retry.
1The error condition allows a retry.

Definition at line 279 of file seams.c.

References BIO_should_retry, g_smtp_test_err_bio_should_retry_ctr, g_smtp_test_err_bio_should_retry_rc, and smtp_test_seam_dec_err_ctr().

279  {
281  return 0;
282  }
285  }
286  return BIO_should_retry(bio);
287 }
int g_smtp_test_err_bio_should_retry_rc
Definition: seams.c:39
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
#define BIO_should_retry
Definition: seams.h:65
int g_smtp_test_err_bio_should_retry_ctr
Definition: seams.c:34
+ Here is the call graph for this function:

◆ smtp_test_seam_calloc()

void* smtp_test_seam_calloc ( size_t  nelem,
size_t  elsize 
)

Allows the test harness to control when calloc() fails.

Parameters
[in]nelemNumber of elements to allocate.
[in]elsizeSize of each element to allocate.
Return values
void*Pointer to new allocated memory.
NULLMemory allocation failed.

Definition at line 298 of file seams.c.

References calloc, g_smtp_test_err_calloc_ctr, and smtp_test_seam_dec_err_ctr().

299  {
301  errno = ENOMEM;
302  return NULL;
303  }
304  return calloc(nelem, elsize);
305 }
#define calloc
Definition: seams.h:73
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_calloc_ctr
Definition: seams.c:44
+ Here is the call graph for this function:

◆ smtp_test_seam_close()

int smtp_test_seam_close ( int  fildes)

Allows the test harness to control when close() fails.

Parameters
[in]fildesSocket file descriptor to close.
Return values
0Successfully closed file descriptor.
-1Failed to close file descriptor.

Definition at line 315 of file seams.c.

References close, g_smtp_test_err_close_ctr, and smtp_test_seam_dec_err_ctr().

315  {
317  errno = EBADF;
318  return -1;
319  }
320  return close(fildes);
321 }
int g_smtp_test_err_close_ctr
Definition: seams.c:49
#define close
Definition: seams.h:81
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_connect()

int smtp_test_seam_connect ( int  socket,
const struct sockaddr *  address,
socklen_t  address_len 
)

Allows the test harness to control when connect() fails.

Parameters
[in]socketSocket connection.
[in]addressNetwork address of peer.
[in]address_lenNumber of bytes in address.
Return values
0Successfully connected to the peer.
-1Failed to connect to the peer.

Definition at line 333 of file seams.c.

References connect, g_smtp_test_err_connect_ctr, and smtp_test_seam_dec_err_ctr().

335  {
337  errno = ECONNREFUSED;
338  return -1;
339  }
340  return connect(socket, address, address_len);
341 }
#define socket
Definition: seams.h:193
#define connect
Definition: seams.h:89
int g_smtp_test_err_connect_ctr
Definition: seams.c:54
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_dec_err_ctr()

int smtp_test_seam_dec_err_ctr ( int *const  test_err_ctr)

Decrement an error counter until it reaches -1.

Once a counter reaches -1, it will return a successful response (1). This typically gets used to denote when to cause a function to fail. For example, the unit test or functional test might need to cause the realloc() function to fail after calling it the third time.

Parameters
[in,out]test_err_ctrInteger counter to decrement.
Return values
0The counter has been decremented, but did not reach -1 yet.
1The counter has reached -1.

Definition at line 244 of file seams.c.

Referenced by smtp_si_add_size_t(), smtp_si_mul_size_t(), smtp_si_sub_size_t(), smtp_test_seam_bio_new_socket(), smtp_test_seam_bio_should_retry(), smtp_test_seam_calloc(), smtp_test_seam_close(), smtp_test_seam_connect(), smtp_test_seam_err_peek_error(), smtp_test_seam_fclose(), smtp_test_seam_ferror(), smtp_test_seam_gmtime_r(), smtp_test_seam_hmac(), smtp_test_seam_localtime_r(), smtp_test_seam_malloc(), smtp_test_seam_mktime(), smtp_test_seam_realloc(), smtp_test_seam_recv(), smtp_test_seam_select(), smtp_test_seam_send(), smtp_test_seam_socket(), smtp_test_seam_sprintf(), smtp_test_seam_ssl_connect(), smtp_test_seam_ssl_ctx_new(), smtp_test_seam_ssl_do_handshake(), smtp_test_seam_ssl_get_peer_certificate(), smtp_test_seam_ssl_new(), smtp_test_seam_ssl_read(), smtp_test_seam_ssl_write(), and smtp_test_seam_x509_check_host().

244  {
245  if(*test_err_ctr >= 0){
246  *test_err_ctr -= 1;
247  if(*test_err_ctr < 0){
248  return 1;
249  }
250  }
251  return 0;
252 }
+ Here is the caller graph for this function:

◆ smtp_test_seam_err_peek_error()

unsigned long smtp_test_seam_err_peek_error ( void  )

Allows the test harness to control when ERR_peek_error() returns a failure code.

Return values
0No error code on the error queue.
!0An error code exists on the error queue.

Definition at line 351 of file seams.c.

References ERR_peek_error, g_smtp_test_err_err_peek_error_ctr, and smtp_test_seam_dec_err_ctr().

351  {
353  return 1;
354  }
355  return ERR_peek_error();
356 }
int g_smtp_test_err_err_peek_error_ctr
Definition: seams.c:60
#define ERR_peek_error
Definition: seams.h:97
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_fclose()

int smtp_test_seam_fclose ( FILE *  stream)

Allows the test harness to control when fclose() fails.

Parameters
[in]streamFile stream to close.
Return values
0Successfully closed the file stream.
EOFAn error occurred while closing the file stream.

Definition at line 365 of file seams.c.

References fclose, g_smtp_test_err_fclose_ctr, and smtp_test_seam_dec_err_ctr().

365  {
367  errno = EBADF;
368  return EOF;
369  }
370  return fclose(stream);
371 }
int g_smtp_test_err_fclose_ctr
Definition: seams.c:65
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
#define fclose
Definition: seams.h:105
+ Here is the call graph for this function:

◆ smtp_test_seam_ferror()

int smtp_test_seam_ferror ( FILE *  stream)

Allows the test harness to control the file stream error indicator return value in ferror().

Parameters
[in]streamCheck for errors on this file stream.
Return values
0No errors detected on the file stream.
1An error occurred during a file stream operation.

Definition at line 382 of file seams.c.

References ferror, g_smtp_test_err_ferror_ctr, and smtp_test_seam_dec_err_ctr().

382  {
384  return 1;
385  }
386  return ferror(stream);
387 }
#define ferror
Definition: seams.h:113
int g_smtp_test_err_ferror_ctr
Definition: seams.c:70
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_gmtime_r()

struct tm* smtp_test_seam_gmtime_r ( const time_t *  timep,
struct tm *  result 
)

Allows the test harness to control when gmtime_r() fails.

Parameters
[in]timepTime value to convert to a struct tm.
[out]resultConverts the timep value into a UTC tm structure value and stores the results in this pointer.
Return values
tm*time_t value converted to a tm structure value.
NULLAn error occurred while converting the time.

Definition at line 399 of file seams.c.

References g_smtp_test_err_gmtime_r_ctr, gmtime_r, and smtp_test_seam_dec_err_ctr().

400  {
402  return NULL;
403  }
404  return gmtime_r(timep, result);
405 }
#define gmtime_r
Definition: seams.h:121
int g_smtp_test_err_gmtime_r_ctr
Definition: seams.c:75
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_hmac()

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 
)

Allows the test harness to control when HMAC() fails.

Parameters
[in]evp_mdHash function.
[in]keyHash key.
[in]key_lenNumber of bytes in key.
[in]dMessage data.
[in]nNumber of bytes in d.
[out]mdThe computed message authentication code.
[in]md_lenNumber of bytes in md.
Return values
uchar*Pointer to md.
NULLAn error occurred.

Definition at line 421 of file seams.c.

References g_smtp_test_err_hmac_ctr, HMAC, and smtp_test_seam_dec_err_ctr().

427  {
429  return NULL;
430  }
431  return HMAC(evp_md, key, key_len, d, n, md, md_len);
432 }
#define HMAC
Definition: seams.h:129
int g_smtp_test_err_hmac_ctr
Definition: seams.c:80
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_localtime_r()

struct tm* smtp_test_seam_localtime_r ( const time_t *  timep,
struct tm *  result 
)

Allows the test harness to control when localtime_r() fails.

Parameters
[in]timepTime value to convert to a struct tm.
[out]resultConverts the timep value into a local time tm structure value and stores the results in this pointer.
Return values
tm*time_t value converted to a tm structure value.
NULLAn error occurred while converting the time.

Definition at line 444 of file seams.c.

References g_smtp_test_err_localtime_r_ctr, localtime_r, and smtp_test_seam_dec_err_ctr().

445  {
447  return NULL;
448  }
449  return localtime_r(timep, result);
450 }
int g_smtp_test_err_localtime_r_ctr
Definition: seams.c:86
#define localtime_r
Definition: seams.h:137
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_malloc()

void* smtp_test_seam_malloc ( size_t  size)

Allows the test harness to control when malloc() fails.

Parameters
[in]sizeNumber of bytes to allocate.
Return values
void*Pointer to new allocated memory.
NULLMemory allocation failed.

Definition at line 460 of file seams.c.

References g_smtp_test_err_malloc_ctr, malloc, and smtp_test_seam_dec_err_ctr().

460  {
462  errno = ENOMEM;
463  return NULL;
464  }
465  return malloc(size);
466 }
#define malloc
Definition: seams.h:145
int g_smtp_test_err_malloc_ctr
Definition: seams.c:91
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_mktime()

time_t smtp_test_seam_mktime ( struct tm *  timeptr)

Allows the test harness to control when mktime() fails.

Parameters
[in]timeptrtm data structure to convert to time_t.
Return values
>=0Time since the epoch.
-1Failed to convert the time.

Definition at line 476 of file seams.c.

References g_smtp_test_err_mktime_ctr, mktime, and smtp_test_seam_dec_err_ctr().

476  {
478  return -1;
479  }
480  return mktime(timeptr);
481 }
int g_smtp_test_err_mktime_ctr
Definition: seams.c:96
#define mktime
Definition: seams.h:153
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_realloc()

void* smtp_test_seam_realloc ( void *  ptr,
size_t  size 
)

Allows the test harness to control when realloc() fails.

Parameters
[in]ptrPreviously allocated memory or NULL memory has not been allocated yet.
[in]sizeNumber of bytes to reallocate.
Return values
void*Pointer to new allocated memory.
NULLMemory allocation failed.

Definition at line 493 of file seams.c.

References g_smtp_test_err_realloc_ctr, realloc, and smtp_test_seam_dec_err_ctr().

494  {
496  errno = ENOMEM;
497  return NULL;
498  }
499  return realloc(ptr, size);
500 }
#define realloc
Definition: seams.h:161
int g_smtp_test_err_realloc_ctr
Definition: seams.c:101
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_recv()

long smtp_test_seam_recv ( int  socket,
void *  buffer,
size_t  length,
int  flags 
)

Allows the test harness to control when recv() fails.

Parameters
[in]socketTCP network socket.
[in]bufferStore received data in this buffer.
[in]lengthNumber of bytes in buffer.
[in]flagsSet this to 0.
Return values
>=0Number of bytes received.
-1Failed to receive bytes over the network.

Definition at line 513 of file seams.c.

References g_smtp_test_err_recv_bytes, g_smtp_test_err_recv_ctr, g_smtp_test_err_recv_rc, recv, smtp_test_seam_dec_err_ctr(), and strlen.

516  {
517  size_t bytes_inject_len;
518 
520  if(g_smtp_test_err_recv_rc != -1){
522  }
524  bytes_inject_len = strlen(g_smtp_test_err_recv_bytes);
525  assert(bytes_inject_len < length && bytes_inject_len < LONG_MAX);
526  memcpy(buffer, g_smtp_test_err_recv_bytes, bytes_inject_len);
527  return (long)bytes_inject_len;
528  }
529  errno = EBADF;
530  return -1;
531  }
532  return recv(socket, buffer, length, flags);
533 }
int g_smtp_test_err_recv_rc
Definition: seams.c:111
int g_smtp_test_err_recv_ctr
Definition: seams.c:106
#define recv
Definition: seams.h:169
#define socket
Definition: seams.h:193
char g_smtp_test_err_recv_bytes[90]
Definition: seams.c:116
#define strlen
Definition: seams.h:273
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_select()

int smtp_test_seam_select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  errorfds,
struct timeval *  timeout 
)

Allows the test harness to control when select() fails.

Parameters
[in]nfdsCheck for file descriptors in range 0 to (nfds - 1) which have any of the read/write/error conditions.
[in]readfdsChecks for file descriptors in fd_set that have bytes ready for reading.
[in]writefdsChecks for file descriptors in fd_set that have bytes ready for writing.
[in]errorfdsChecks for file descriptors in fd_set that have errors pending.
[in]timeoutWait for the read/write/error conditions in blocking mode until this timeout or an interrupt occurs.
Return values
>=0Number of bits set in the bitmask.
-1An error occurred.

Definition at line 552 of file seams.c.

References g_smtp_test_err_select_ctr, select, and smtp_test_seam_dec_err_ctr().

556  {
558  errno = EINTR;
559  return -1;
560  }
561  return select(nfds, readfds, writefds, errorfds, timeout);
562 }
int g_smtp_test_err_select_ctr
Definition: seams.c:121
#define select
Definition: seams.h:177
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_send()

ssize_t smtp_test_seam_send ( int  socket,
const void *  buffer,
size_t  length,
int  flags 
)

Allows the test harness to control when send() fails.

Parameters
[in]socketTCP network socket.
[in]bufferData to send over the network.
[in]lengthNumber of bytes in buffer.
[in]flagsSet this to 0.
Return values
>=0Number of bytes sent.
-1Failed to send bytes over the network.

Definition at line 575 of file seams.c.

References g_smtp_test_err_send_ctr, g_smtp_test_send_one_byte, send, and smtp_test_seam_dec_err_ctr().

578  {
579  long sent_bytes;
580  size_t bytes_to_send;
581 
583  errno = EBADF;
584  sent_bytes = -1;
585  }
586  else{
587  bytes_to_send = length;
589  bytes_to_send = 1;
590  }
591  sent_bytes = send(socket, buffer, bytes_to_send, flags);
592  }
593  return sent_bytes;
594 }
#define socket
Definition: seams.h:193
int g_smtp_test_send_one_byte
Definition: seams.c:131
#define send
Definition: seams.h:185
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_send_ctr
Definition: seams.c:126
+ Here is the call graph for this function:

◆ smtp_test_seam_socket()

int smtp_test_seam_socket ( int  domain,
int  type,
int  protocol 
)

Allows the test harness to control when socket() fails.

Parameters
[in]domainSocket domain.
[in]typeSocket type.
[in]protocolSocket protocol.
Return values
!(-1)The file descriptor for the new socket.
-1Failed to create the socket.

Definition at line 606 of file seams.c.

References g_smtp_test_err_socket_ctr, smtp_test_seam_dec_err_ctr(), and socket.

608  {
610  errno = EINVAL;
611  return -1;
612  }
613  return socket(domain, type, protocol);
614 }
#define socket
Definition: seams.h:193
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_socket_ctr
Definition: seams.c:154
+ Here is the call graph for this function:

◆ smtp_test_seam_sprintf()

int smtp_test_seam_sprintf ( char *  s,
const char *  format,
  ... 
)

Allows the test harness to control when sprintf() fails.

Parameters
[in]sBuffer to store the output contents to.
[in]formatFormat string defined in sprintf().
Return values
>=0Number of bytes copied to s, excluding the null-terminator.
<0Output or formatting error.

Definition at line 771 of file seams.c.

References g_smtp_test_err_sprintf_ctr, g_smtp_test_err_sprintf_rc, and smtp_test_seam_dec_err_ctr().

772  {
773  va_list ap;
774  int rc;
775 
777  errno = ENOMEM;
779  }
780  va_start(ap, format);
781  rc = vsprintf(s, format, ap);
782  va_end(ap);
783  return rc;
784 }
int g_smtp_test_err_sprintf_ctr
Definition: seams.c:204
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_sprintf_rc
Definition: seams.c:209
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_connect()

int smtp_test_seam_ssl_connect ( SSL *  ssl)

Allows the test harness to control when SSL_connect() fails.

Parameters
[in]sslOpenSSL handle.
Return values
1TLS connection handshake successful.
<1TLS connection handshake failed.

Definition at line 624 of file seams.c.

References g_smtp_test_err_ssl_connect_ctr, smtp_test_seam_dec_err_ctr(), and SSL_connect.

624  {
626  return 0;
627  }
628  return SSL_connect(ssl);
629 }
int g_smtp_test_err_ssl_connect_ctr
Definition: seams.c:160
#define SSL_connect
Definition: seams.h:201
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_ctx_new()

SSL_CTX* smtp_test_seam_ssl_ctx_new ( const SSL_METHOD *  method)

Allows the test harness to control when SSL_CTX_new() fails.

Parameters
[in]methodTLS connection method.
Return values
SSL_CTX*Pointer to new TLS context.
NULLFailed to create new TLS context.

Definition at line 639 of file seams.c.

References g_smtp_test_err_ssl_ctx_new_ctr, smtp_test_seam_dec_err_ctr(), and SSL_CTX_new.

639  {
641  return NULL;
642  }
643  return SSL_CTX_new(method);
644 }
#define SSL_CTX_new
Definition: seams.h:209
int g_smtp_test_err_ssl_ctx_new_ctr
Definition: seams.c:166
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_do_handshake()

int smtp_test_seam_ssl_do_handshake ( SSL *  ssl)

Allows the test harness to control when SSL_do_handshake() fails.

Parameters
[in]sslOpenSSL handle.
Return values
1TLS handshake successful.
<1TLS handshake failed.

Definition at line 654 of file seams.c.

References g_smtp_test_err_ssl_do_handshake_ctr, smtp_test_seam_dec_err_ctr(), and SSL_do_handshake.

654  {
656  return 0;
657  }
658  return SSL_do_handshake(ssl);
659 }
#define SSL_do_handshake
Definition: seams.h:217
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_ssl_do_handshake_ctr
Definition: seams.c:172
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_get_peer_certificate()

X509* smtp_test_seam_ssl_get_peer_certificate ( const SSL *  ssl)

Allows the test harness to control when SSL_get_peer_certificate() fails.

Parameters
[in]sslOpenSSL handle.
Return values
X509*Peer certficate which must get freed by using X509_free().
NULLFailed to get the peer certificate.

Definition at line 669 of file seams.c.

References g_smtp_test_err_ssl_get_peer_certificate_ctr, smtp_test_seam_dec_err_ctr(), and SSL_get_peer_certificate.

669  {
671  return NULL;
672  }
673  return SSL_get_peer_certificate(ssl);
674 }
int g_smtp_test_err_ssl_get_peer_certificate_ctr
Definition: seams.c:178
#define SSL_get_peer_certificate
Definition: seams.h:225
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_new()

SSL* smtp_test_seam_ssl_new ( SSL_CTX *  ctx)

Allows the test harness to control when SSL_new() fails.

Parameters
[in]ctxOpenSSL TLS context.
Return values
SSL*Pointer to a new TLS context.
NULLFailed to create new TLS context.

Definition at line 709 of file seams.c.

References g_smtp_test_err_ssl_new_ctr, smtp_test_seam_dec_err_ctr(), and SSL_new.

709  {
711  return NULL;
712  }
713  return SSL_new(ctx);
714 }
int g_smtp_test_err_ssl_new_ctr
Definition: seams.c:189
#define SSL_new
Definition: seams.h:241
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_read()

int smtp_test_seam_ssl_read ( SSL *  ssl,
void *  buf,
int  num 
)

Allows the test harness to control when SSL_read() fails.

Parameters
[in]sslOpenSSL TLS object.
[in]bufStore received data in this buffer.
[in]numNumber of bytes in buf.
Return values
>0Number of bytes successfully read from the TLS connection.
<=0Failed to read bytes on the TLS connection.

Definition at line 726 of file seams.c.

References g_smtp_test_err_recv_bytes, g_smtp_test_err_ssl_read_ctr, smtp_test_seam_dec_err_ctr(), SSL_read, and strlen.

728  {
729  size_t bytes_inject_len;
730 
733  bytes_inject_len = strlen(g_smtp_test_err_recv_bytes);
734  assert(bytes_inject_len < (size_t)num && bytes_inject_len < INT_MAX);
735  memcpy(buf, g_smtp_test_err_recv_bytes, bytes_inject_len);
736  return (int)bytes_inject_len;
737  }
738  return -1;
739  }
740  return SSL_read(ssl, buf, num);
741 }
int g_smtp_test_err_ssl_read_ctr
Definition: seams.c:194
#define SSL_read
Definition: seams.h:249
char g_smtp_test_err_recv_bytes[90]
Definition: seams.c:116
#define strlen
Definition: seams.h:273
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_write()

int smtp_test_seam_ssl_write ( SSL *  ssl,
const void *  buf,
int  num 
)

Allows the test harness to control when SSL_write() fails.

Parameters
[in]sslOpenSSL TLS object.
[in]bufData to write to the TLS connection.
[in]numNumber of bytes in buf.
Return values
>0Number of bytes successfully written to the TLS connection.
<=0Failed to write bytes to the TLS connection.

Definition at line 753 of file seams.c.

References g_smtp_test_err_ssl_write_ctr, smtp_test_seam_dec_err_ctr(), and SSL_write.

755  {
757  return -1;
758  }
759  return SSL_write(ssl, buf, num);
760 }
#define SSL_write
Definition: seams.h:257
int g_smtp_test_err_ssl_write_ctr
Definition: seams.c:199
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_strlen()

size_t smtp_test_seam_strlen ( const char *  s)

Allows the test harness to control the return value of strlen().

Parameters
[in]sNull-terminated string.
Returns
Length of s.

Definition at line 793 of file seams.c.

References g_smtp_test_strlen_custom_ret, g_smtp_test_strlen_ret_value, and strlen.

793  {
794  size_t result;
795 
798  }
799  else{
800  result = strlen(s);
801  }
802  return result;
803 }
int g_smtp_test_strlen_custom_ret
Definition: seams.c:214
size_t g_smtp_test_strlen_ret_value
Definition: seams.c:219
#define strlen
Definition: seams.h:273

◆ smtp_test_seam_time()

time_t smtp_test_seam_time ( time_t *  tloc)

Allows the test harness to control when time() fails.

Parameters
[out]tlocBuffer to hold the time_t results.
Return values
>=0Time in seconds since the Epoch.
-1Failed to store the time in tloc.

Definition at line 813 of file seams.c.

References g_smtp_test_time_custom_ret, g_smtp_test_time_ret_value, and time.

813  {
816  }
817  return time(tloc);
818 }
#define time
Definition: seams.h:281
int g_smtp_test_time_custom_ret
Definition: seams.c:224
time_t g_smtp_test_time_ret_value
Definition: seams.c:229

◆ smtp_test_seam_x509_check_host()

int smtp_test_seam_x509_check_host ( X509 *  cert,
const char *  name,
size_t  namelen,
unsigned int  flags,
char **  peername 
)

Allows the test harness to control when X509_check_host() fails.

Parameters
[in]certX509 certificate handle.
[in]nameServer name.
[in]namelenNumber of characters in name or 0 if null-terminated.
[in]flagsUsually set to 0.
[in]peernamePointer to CN from certificate stored in this buffer if not NULL.
Return values
1Successful host check.
0Failed host check.
-1Internal error.

Definition at line 690 of file seams.c.

References g_smtp_test_err_x509_check_host_ctr, smtp_test_seam_dec_err_ctr(), and X509_check_host.

694  {
696  return -1;
697  }
698  return X509_check_host(cert, name, namelen, flags, peername);
699 }
int g_smtp_test_err_x509_check_host_ctr
Definition: seams.c:184
#define X509_check_host
Definition: seams.h:233
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_utf8_charlen()

size_t smtp_utf8_charlen ( char  c)

Get the length in bytes of a UTF-8 character.

This consists of a very simple check and assumes the user provides a valid UTF-8 byte sequence. It gets the length from the first byte in the sequence and does not validate any other bytes in the character sequence or any other bits in the first byte of the character sequence.

Parameters
[in]cThe first byte in a valid UTF-8 character sequence.
Return values
>0Number of bytes for the current UTF-8 character sequence.
-1Invalid byte sequence.

Definition at line 1078 of file smtp.c.

References SMTP_LINKAGE.

Referenced by smtp_str_has_nonascii_utf8(), smtp_strnlen_utf8(), and smtp_unit_test_all_smtp_utf8_charlen().

1078  {
1079  unsigned char uc;
1080 
1081  uc = (unsigned char)c;
1082  if((uc & 0x80) == 0){ /* 0XXXXXXX */
1083  return 1;
1084  }
1085  else if((uc & 0xE0) == 0xC0){ /* 110XXXXX */
1086  return 2;
1087  }
1088  else if((uc & 0xF0) == 0xE0){ /* 1110XXXX */
1089  return 3;
1090  }
1091  else if((uc & 0xF8) == 0xF0){ /* 11110XXX */
1092  return 4;
1093  }
1094  else{ /* invalid */
1095  return 0;
1096  }
1097 }
+ Here is the caller graph for this function:

◆ smtp_write()

enum smtp_status_code smtp_write ( struct smtp *const  smtp,
const char *const  buf,
size_t  len 
)

Send data to the SMTP server.

Writes a buffer of length len into either the unencrypted TCP socket or the TLS encrypted socket, depending on the current underlying mode of the socket.

Parameters
[in]smtpSMTP client context.
[in]bufData to send to the SMTP server.
[in]lenNumber of bytes in buf.
Returns
See smtp_status_code.

Definition at line 1603 of file smtp.c.

References send, smtp_puts_dbg(), smtp_status_code_set(), SMTP_STATUS_SEND, smtp::sock, SSL_write, smtp::status_code, smtp::tls, and smtp::tls_on.

Referenced by smtp_puts(), and test_failure_misc().

1605  {
1606  size_t bytes_to_send;
1607  long bytes_sent;
1608  const char *buf_offset;
1609  int ssl_bytes_to_send;
1610 
1611  smtp_puts_dbg(smtp, "Client", buf);
1612 
1613  bytes_to_send = len;
1614  buf_offset = buf;
1615  while(bytes_to_send){
1616  if(bytes_to_send > INT_MAX){
1617  return smtp_status_code_set(smtp, SMTP_STATUS_SEND);
1618  }
1619 
1620  if(smtp->tls_on){
1621 #ifdef SMTP_OPENSSL
1622  /* bytes_to_send <= INT_MAX */
1623  ssl_bytes_to_send = (int)bytes_to_send;
1624  bytes_sent = SSL_write(smtp->tls, buf_offset, ssl_bytes_to_send);
1625  if(bytes_sent <= 0){
1626  return smtp_status_code_set(smtp, SMTP_STATUS_SEND);
1627  }
1628 #else /* !(SMTP_OPENSSL) */
1629  /* unreachable */
1630  bytes_sent = 0;
1631  (void)ssl_bytes_to_send;
1632 #endif /* SMTP_OPENSSL */
1633  }
1634  else{
1635  bytes_sent = send(smtp->sock, buf_offset, bytes_to_send, 0);
1636  if(bytes_sent < 0){
1637  return smtp_status_code_set(smtp, SMTP_STATUS_SEND);
1638  }
1639  }
1640  bytes_to_send -= (size_t)bytes_sent;
1641  buf_offset += bytes_sent;
1642  }
1643 
1644  return smtp->status_code;
1645 }
int tls_on
Definition: smtp.c:215
#define SSL_write
Definition: seams.h:257
enum smtp_status_code smtp_status_code_set(struct smtp *const smtp, enum smtp_status_code status_code)
Definition: smtp.c:3231
#define send
Definition: seams.h:185
enum smtp_status_code status_code
Definition: smtp.c:208
SSL * tls
Definition: smtp.c:227
int sock
Definition: smtp.c:159
static void smtp_puts_dbg(struct smtp *const smtp, const char *const prefix, const char *const str)
Definition: smtp.c:1512
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ g_smtp_test_err_bio_new_socket_ctr

int g_smtp_test_err_bio_new_socket_ctr

◆ g_smtp_test_err_bio_should_retry_ctr

int g_smtp_test_err_bio_should_retry_ctr

◆ g_smtp_test_err_bio_should_retry_rc

int g_smtp_test_err_bio_should_retry_rc

Value to force the BIO_should_retry() function to return.

This value will only get returned if g_smtp_test_err_bio_should_retry_ctr has a value of 0 and this does not have a value of -1.

See g_smtp_test_err_bio_should_retry_rc.

Definition at line 39 of file seams.c.

Referenced by smtp_test_seam_bio_should_retry(), and test_failure_open().

◆ g_smtp_test_err_calloc_ctr

◆ g_smtp_test_err_close_ctr

int g_smtp_test_err_close_ctr

Counter for smtp_test_seam_close.

See test_seams_countdown_global for more details.

See g_smtp_test_err_close_ctr and test_seams_countdown_global.

Definition at line 49 of file seams.c.

Referenced by smtp_test_seam_close(), and test_failure_close().

◆ g_smtp_test_err_connect_ctr

int g_smtp_test_err_connect_ctr

◆ g_smtp_test_err_err_peek_error_ctr

int g_smtp_test_err_err_peek_error_ctr

◆ g_smtp_test_err_fclose_ctr

int g_smtp_test_err_fclose_ctr

◆ g_smtp_test_err_ferror_ctr

int g_smtp_test_err_ferror_ctr

◆ g_smtp_test_err_gmtime_r_ctr

int g_smtp_test_err_gmtime_r_ctr

◆ g_smtp_test_err_hmac_ctr

int g_smtp_test_err_hmac_ctr

◆ g_smtp_test_err_localtime_r_ctr

int g_smtp_test_err_localtime_r_ctr

◆ g_smtp_test_err_malloc_ctr

◆ g_smtp_test_err_mktime_ctr

int g_smtp_test_err_mktime_ctr

◆ g_smtp_test_err_realloc_ctr

◆ g_smtp_test_err_recv_bytes

char g_smtp_test_err_recv_bytes[90]

Set the received bytes in recv() and SSL_read() to this value if it contains a null-terminated string at least one bytes long.

This makes it easier to inject a bad server response for testing the smtp-client handling of those bad responses.

See test_seams_countdown_global for more details.

See g_smtp_test_err_recv_bytes and test_seams_countdown_global.

Definition at line 116 of file seams.c.

Referenced by smtp_test_seam_recv(), smtp_test_seam_ssl_read(), and test_failure_auth().

◆ g_smtp_test_err_recv_ctr

int g_smtp_test_err_recv_ctr

◆ g_smtp_test_err_recv_rc

int g_smtp_test_err_recv_rc

Value to force the recv() function to return.

This value will only get returned if g_smtp_test_err_recv_ctr has a value of 0 and this does not have a value of -1.

See g_smtp_test_err_recv_rc.

Definition at line 111 of file seams.c.

Referenced by smtp_test_seam_recv(), and test_failure_open().

◆ g_smtp_test_err_select_ctr

int g_smtp_test_err_select_ctr

◆ g_smtp_test_err_send_ctr

◆ g_smtp_test_err_si_add_size_t_ctr

◆ g_smtp_test_err_si_mul_size_t_ctr

int g_smtp_test_err_si_mul_size_t_ctr

◆ g_smtp_test_err_si_sub_size_t_ctr

int g_smtp_test_err_si_sub_size_t_ctr

◆ g_smtp_test_err_socket_ctr

int g_smtp_test_err_socket_ctr

◆ g_smtp_test_err_sprintf_ctr

int g_smtp_test_err_sprintf_ctr

◆ g_smtp_test_err_sprintf_rc

int g_smtp_test_err_sprintf_rc

Value to force the sprintf() function to return.

This value will only get returned if g_smtp_test_err_sprintf_ctr has a value of 0.

See g_smtp_test_err_sprintf_rc.

Definition at line 209 of file seams.c.

Referenced by smtp_test_seam_sprintf(), smtp_unit_test_all_bin2hex(), and smtp_unit_test_all_date_rfc_2822().

◆ g_smtp_test_err_ssl_connect_ctr

int g_smtp_test_err_ssl_connect_ctr

◆ g_smtp_test_err_ssl_ctx_new_ctr

int g_smtp_test_err_ssl_ctx_new_ctr

◆ g_smtp_test_err_ssl_do_handshake_ctr

int g_smtp_test_err_ssl_do_handshake_ctr

◆ g_smtp_test_err_ssl_get_peer_certificate_ctr

int g_smtp_test_err_ssl_get_peer_certificate_ctr

◆ g_smtp_test_err_ssl_new_ctr

int g_smtp_test_err_ssl_new_ctr

◆ g_smtp_test_err_ssl_read_ctr

int g_smtp_test_err_ssl_read_ctr

◆ g_smtp_test_err_ssl_write_ctr

◆ g_smtp_test_err_x509_check_host_ctr

int g_smtp_test_err_x509_check_host_ctr

◆ g_smtp_test_send_one_byte

int g_smtp_test_send_one_byte

Indicate if we should only send one byte at a time.

See g_smtp_test_send_one_byte.

Definition at line 131 of file seams.c.

Referenced by smtp_func_test_all_write(), and smtp_test_seam_send().

◆ g_smtp_test_strlen_custom_ret

int g_smtp_test_strlen_custom_ret

Indicates if the strlen() function should return a test value.

This can get set to one of two values:

See g_smtp_test_strlen_custom_ret.

Definition at line 214 of file seams.c.

Referenced by smtp_test_seam_strlen(), smtp_unit_test_all_base64_encode(), smtp_unit_test_all_str_replace(), smtp_unit_test_all_strdup(), and test_failure_mail().

◆ g_smtp_test_strlen_ret_value

size_t g_smtp_test_strlen_ret_value

Value to force the strlen() function to return.

This value will only get returned if g_smtp_test_strlen_custom_ret has been set.

See g_smtp_test_strlen_ret_value.

Definition at line 219 of file seams.c.

Referenced by smtp_test_seam_strlen(), smtp_unit_test_all_base64_encode(), smtp_unit_test_all_str_replace(), smtp_unit_test_all_strdup(), and test_failure_mail().

◆ g_smtp_test_time_custom_ret

int g_smtp_test_time_custom_ret

Indicates if the time() function should return a custom value.

This can get set to one of two values:

See g_smtp_test_time_custom_ret.

Definition at line 224 of file seams.c.

Referenced by smtp_test_seam_time(), and smtp_unit_test_date_rfc_2822().

◆ g_smtp_test_time_ret_value

time_t g_smtp_test_time_ret_value

Value to force the time() function to return.

This value will only get returned if g_smtp_test_time_custom_ret has a positive value.

See g_smtp_test_time_ret_value.

Definition at line 229 of file seams.c.

Referenced by smtp_test_seam_time(), and smtp_unit_test_date_rfc_2822().