libspf2 1.2.11
Data Structures | Enumerations | Functions
spf_response.h File Reference
#include "spf.h"
#include "spf_request.h"
Include dependency graph for spf_response.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SPF_error_t
 
struct  SPF_response_t
 

Enumerations

enum  SPF_result_t {
  SPF_RESULT_INVALID = 0 , SPF_RESULT_NEUTRAL , SPF_RESULT_PASS , SPF_RESULT_FAIL ,
  SPF_RESULT_SOFTFAIL , SPF_RESULT_NONE , SPF_RESULT_TEMPERROR , SPF_RESULT_PERMERROR
}
 
enum  SPF_reason_t {
  SPF_REASON_NONE = 0 , SPF_REASON_FAILURE , SPF_REASON_LOCALHOST , SPF_REASON_LOCAL_POLICY ,
  SPF_REASON_MECH , SPF_REASON_DEFAULT , SPF_REASON_2MX
}
 
enum  SPF_errcode_t {
  SPF_E_SUCCESS = 0 , SPF_E_NO_MEMORY , SPF_E_NOT_SPF , SPF_E_SYNTAX ,
  SPF_E_MOD_W_PREF , SPF_E_INVALID_CHAR , SPF_E_UNKNOWN_MECH , SPF_E_INVALID_OPT ,
  SPF_E_INVALID_CIDR , SPF_E_MISSING_OPT , SPF_E_INTERNAL_ERROR , SPF_E_INVALID_ESC ,
  SPF_E_INVALID_VAR , SPF_E_BIG_SUBDOM , SPF_E_INVALID_DELIM , SPF_E_BIG_STRING ,
  SPF_E_BIG_MECH , SPF_E_BIG_MOD , SPF_E_BIG_DNS , SPF_E_INVALID_IP4 ,
  SPF_E_INVALID_IP6 , SPF_E_INVALID_PREFIX , SPF_E_RESULT_UNKNOWN , SPF_E_UNINIT_VAR ,
  SPF_E_MOD_NOT_FOUND , SPF_E_NOT_CONFIG , SPF_E_DNS_ERROR , SPF_E_BAD_HOST_IP ,
  SPF_E_BAD_HOST_TLD , SPF_E_MECH_AFTER_ALL , SPF_E_INCLUDE_RETURNED_NONE , SPF_E_RECURSIVE ,
  SPF_E_MULTIPLE_RECORDS
}
 

Functions

SPF_response_t * SPF_response_new (SPF_request_t *spf_request)
 
void SPF_response_free (SPF_response_t *rp)
 
SPF_response_t * SPF_response_combine (SPF_response_t *main, SPF_response_t *r2mx)
 
SPF_result_t SPF_response_result (SPF_response_t *rp)
 
SPF_reason_t SPF_response_reason (SPF_response_t *rp)
 
SPF_errcode_t SPF_response_errcode (SPF_response_t *rp)
 
const char * SPF_response_get_received_spf (SPF_response_t *rp)
 
const char * SPF_response_get_received_spf_value (SPF_response_t *rp)
 
const char * SPF_response_get_header_comment (SPF_response_t *rp)
 
const char * SPF_response_get_smtp_comment (SPF_response_t *rp)
 
const char * SPF_response_get_explanation (SPF_response_t *rp)
 
int SPF_response_messages (SPF_response_t *rp)
 
int SPF_response_errors (SPF_response_t *rp)
 
int SPF_response_warnings (SPF_response_t *rp)
 
SPF_error_tSPF_response_message (SPF_response_t *rp, int idx)
 
SPF_errcode_t SPF_error_code (SPF_error_t *err)
 
const char * SPF_error_message (SPF_error_t *err)
 
char SPF_error_errorp (SPF_error_t *err)
 
SPF_errcode_t SPF_response_add_error_ptr (SPF_response_t *rp, SPF_errcode_t code, const char *text, const char *tptr, const char *format,...)
 
SPF_errcode_t SPF_response_add_error_idx (SPF_response_t *rp, SPF_errcode_t code, const char *text, int idx, const char *format,...)
 
SPF_errcode_t SPF_response_add_error (SPF_response_t *rp, SPF_errcode_t code, const char *format,...)
 
SPF_errcode_t SPF_response_add_warn_ptr (SPF_response_t *rp, SPF_errcode_t code, const char *text, const char *tptr, const char *format,...)
 
SPF_errcode_t SPF_response_add_warn_idx (SPF_response_t *rp, SPF_errcode_t code, const char *text, int idx, const char *format,...)
 
SPF_errcode_t SPF_response_add_warn (SPF_response_t *rp, SPF_errcode_t code, const char *format,...)
 

Detailed Description

Results from an SPF check

The results of the SPF check (as defined by the official SPF spec)

To quote from doc/draft-mengwong-spf-00.txt Section 3:

3. SPF Record Evaluation

   An SPF client evaluates an SPF record and produces one of seven
   results:

     None: The domain does not publish SPF data.

     Neutral (?): The SPF client MUST proceed as if a domain did not
     publish SPF data.  This result occurs if the domain explicitly
     specifies a "?" value, or if processing "falls off the end" of
     the SPF record.

     Pass (+): the message meets the publishing domain's definition of
     legitimacy.  MTAs proceed to apply local policy and MAY accept or
     reject the message accordingly.

     Fail (-): the message does not meet a domain's definition of
     legitimacy.  MTAs MAY reject the message using a permanent
     failure reply code.  (Code 550 is RECOMMENDED.  See RFC2821
     section 7.1.)

     Softfail (~): the message does not meet a domain's strict
     definition of legitimacy, but the domain cannot confidently state
     that the message is a forgery.  MTAs SHOULD accept the message
     but MAY subject it to a higher transaction cost, deeper scrutiny,
     or an unfavourable score.

   There are two error conditions, one temporary and one permanent.

     Error: indicates an error during lookup; an MTA MAY reject the
     message using a transient failure code, such as 450.

     Unknown: indicates incomplete processing: an MTA MUST proceed as
     if a domain did not publish SPF data.

   When SPF-aware SMTP receivers accept a message, they SHOULD prepend a
   Received-SPF header.  See section 6.

   SPF clients MUST use the algorithm described in this section
   or its functional equivalent.

   If an SPF client encounters a syntax error in an
   SPF record, it must terminate processing and return a result
   of "unknown".

note: SPF_RESULT_* values are constrained by the internal PREFIX_* values

Definition in file spf_response.h.

Enumeration Type Documentation

◆ SPF_errcode_t

error codes returned by various SPF functions. (including SPF_compile() and SPF_id2str(), spf_result(), etc.).

The function SPF_strerror() will return a longer explanation of these errors.

Enumerator
SPF_E_SUCCESS 

No errors

SPF_E_NO_MEMORY 

Out of memory

SPF_E_NOT_SPF 

Could not find a valid SPF record

SPF_E_SYNTAX 

Syntax error

SPF_E_MOD_W_PREF 

Modifiers can not have prefixes

SPF_E_INVALID_CHAR 

Invalid character found

SPF_E_UNKNOWN_MECH 

Unknown mechanism found

SPF_E_INVALID_OPT 

Invalid option found

SPF_E_INVALID_CIDR 

Invalid CIDR length

SPF_E_MISSING_OPT 

Required option is missing

SPF_E_INTERNAL_ERROR 

Internal programming error

SPF_E_INVALID_ESC 

Invalid %-escape character

SPF_E_INVALID_VAR 

Invalid macro variable

SPF_E_BIG_SUBDOM 

Subdomain truncation depth too large

SPF_E_INVALID_DELIM 

Invalid delimiter character

SPF_E_BIG_STRING 

Option string too long

SPF_E_BIG_MECH 

Too many mechanisms

SPF_E_BIG_MOD 

Too many modifiers

SPF_E_BIG_DNS 

Mechanisms used too many DNS lookups

SPF_E_INVALID_IP4 

Invalid IPv4 address literal

SPF_E_INVALID_IP6 

Invalid IPv6 address literal

SPF_E_INVALID_PREFIX 

Invalid mechanism prefix

SPF_E_RESULT_UNKNOWN 

SPF result is "unknown"

SPF_E_UNINIT_VAR 

Uninitialized variable

SPF_E_MOD_NOT_FOUND 

Modifier not found

SPF_E_NOT_CONFIG 

Not configured

SPF_E_DNS_ERROR 

DNS lookup failure

SPF_E_BAD_HOST_IP 

Invalid hostname (an IP address?)

SPF_E_BAD_HOST_TLD 

Hostname has a missing or invalid TLD

SPF_E_MECH_AFTER_ALL 

Mechanisms found after the "all:" mechanism will be ignored

SPF_E_INCLUDE_RETURNED_NONE 

If an include recursive query returns none it's a perm error

SPF_E_RECURSIVE 

Recursive include

SPF_E_MULTIPLE_RECORDS 

Multiple SPF or TXT records found

Definition at line 118 of file spf_response.h.

◆ SPF_reason_t

The reason that the result was returned

This is what triggered the SPF result. Usually, it is a mechanism in the SPF record that causes the result, but if it was something else, the calling program will often want to take a different action or issue a different message.

Enumerator
SPF_REASON_NONE 
SPF_REASON_FAILURE 
SPF_REASON_LOCALHOST 

localhost always gets a free ride

SPF_REASON_LOCAL_POLICY 

local policy caused the match

SPF_REASON_MECH 

mechanism caused the match

SPF_REASON_DEFAULT 

ran off the end of the rec

SPF_REASON_2MX 

sent from a secondary MX

Definition at line 99 of file spf_response.h.

◆ SPF_result_t

Enumerator
SPF_RESULT_INVALID 

We should never return this.

SPF_RESULT_NEUTRAL 
SPF_RESULT_PASS 
SPF_RESULT_FAIL 
SPF_RESULT_SOFTFAIL 
SPF_RESULT_NONE 
SPF_RESULT_TEMPERROR 
SPF_RESULT_PERMERROR 

Definition at line 78 of file spf_response.h.

Function Documentation

◆ SPF_error_code()

SPF_errcode_t SPF_error_code ( SPF_error_t err)

Definition at line 314 of file spf_response.c.

References SPF_error_t::code.

Referenced by main(), and SPF_record_compile().

◆ SPF_error_errorp()

char SPF_error_errorp ( SPF_error_t err)

Definition at line 326 of file spf_response.c.

References SPF_error_t::is_error.

Referenced by main(), and SPF_record_compile().

◆ SPF_error_message()

const char * SPF_error_message ( SPF_error_t err)

Definition at line 320 of file spf_response.c.

References SPF_error_t::message.

Referenced by main().

◆ SPF_response_add_error()

SPF_errcode_t SPF_response_add_error ( SPF_response_t *  rp,
SPF_errcode_t  code,
const char *  format,
  ... 
)

◆ SPF_response_add_error_idx()

SPF_errcode_t SPF_response_add_error_idx ( SPF_response_t *  rp,
SPF_errcode_t  code,
const char *  text,
int  idx,
const char *  format,
  ... 
)

Definition at line 247 of file spf_response.c.

References SPF_ADD_ERROR.

◆ SPF_response_add_error_ptr()

SPF_errcode_t SPF_response_add_error_ptr ( SPF_response_t *  rp,
SPF_errcode_t  code,
const char *  text,
const char *  tptr,
const char *  format,
  ... 
)

Internal functions for adding errors.

Definition at line 238 of file spf_response.c.

References SPF_ADD_ERROR.

Referenced by SPF_record_compile().

◆ SPF_response_add_warn()

SPF_errcode_t SPF_response_add_warn ( SPF_response_t *  rp,
SPF_errcode_t  code,
const char *  format,
  ... 
)

Definition at line 282 of file spf_response.c.

References NULL, and SPF_ADD_WARN.

Referenced by SPF_request_get_exp().

◆ SPF_response_add_warn_idx()

SPF_errcode_t SPF_response_add_warn_idx ( SPF_response_t *  rp,
SPF_errcode_t  code,
const char *  text,
int  idx,
const char *  format,
  ... 
)

Definition at line 273 of file spf_response.c.

References SPF_ADD_WARN.

◆ SPF_response_add_warn_ptr()

SPF_errcode_t SPF_response_add_warn_ptr ( SPF_response_t *  rp,
SPF_errcode_t  code,
const char *  text,
const char *  tptr,
const char *  format,
  ... 
)

Definition at line 264 of file spf_response.c.

References SPF_ADD_WARN.

Referenced by SPF_record_compile().

◆ SPF_response_combine()

SPF_response_t * SPF_response_combine ( SPF_response_t *  main,
SPF_response_t *  r2mx 
)

Definition at line 90 of file spf_response.c.

References main(), SPF_response_result(), SPF_RESULT_FAIL, SPF_RESULT_INVALID, SPF_RESULT_NEUTRAL, SPF_RESULT_PASS, SPF_RESULT_PERMERROR, SPF_RESULT_SOFTFAIL, and SPF_RESULT_TEMPERROR.

Referenced by main().

Here is the call graph for this function:

◆ SPF_response_errcode()

SPF_errcode_t SPF_response_errcode ( SPF_response_t *  rp)

Definition at line 147 of file spf_response.c.

Referenced by main(), and SPF_record_interpret().

◆ SPF_response_errors()

int SPF_response_errors ( SPF_response_t *  rp)

How many errors were generated?

Definition at line 296 of file spf_response.c.

Referenced by main(), and SPF_record_compile().

◆ SPF_response_free()

void SPF_response_free ( SPF_response_t *  rp)

Definition at line 53 of file spf_response.c.

Referenced by main(), and SPF_record_interpret().

◆ SPF_response_get_explanation()

const char * SPF_response_get_explanation ( SPF_response_t *  rp)

Definition at line 177 of file spf_response.c.

◆ SPF_response_get_header_comment()

const char * SPF_response_get_header_comment ( SPF_response_t *  rp)

Definition at line 165 of file spf_response.c.

Referenced by main().

◆ SPF_response_get_received_spf()

const char * SPF_response_get_received_spf ( SPF_response_t *  rp)

Definition at line 153 of file spf_response.c.

Referenced by main().

◆ SPF_response_get_received_spf_value()

const char * SPF_response_get_received_spf_value ( SPF_response_t *  rp)

Definition at line 159 of file spf_response.c.

◆ SPF_response_get_smtp_comment()

const char * SPF_response_get_smtp_comment ( SPF_response_t *  rp)

Definition at line 171 of file spf_response.c.

Referenced by main().

◆ SPF_response_message()

SPF_error_t * SPF_response_message ( SPF_response_t *  rp,
int  idx 
)

Returns an individual message

Definition at line 308 of file spf_response.c.

Referenced by main(), and SPF_record_compile().

◆ SPF_response_messages()

int SPF_response_messages ( SPF_response_t *  rp)

How many warnings were generated?

Definition at line 290 of file spf_response.c.

Referenced by main(), and SPF_record_compile().

◆ SPF_response_new()

SPF_response_t * SPF_response_new ( SPF_request_t *  spf_request)

◆ SPF_response_reason()

SPF_reason_t SPF_response_reason ( SPF_response_t *  rp)

Definition at line 141 of file spf_response.c.

◆ SPF_response_result()

SPF_result_t SPF_response_result ( SPF_response_t *  rp)

Definition at line 135 of file spf_response.c.

Referenced by main(), SPF_record_interpret(), and SPF_response_combine().

◆ SPF_response_warnings()

int SPF_response_warnings ( SPF_response_t *  rp)

Errors + warnings

Definition at line 302 of file spf_response.c.