util.h File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <time.h>
#include <ctype.h>
#include "main.h"

Go to the source code of this file.

Defines

#define _UTIL_H   1
#define SIZEOF(object)   ((size_t) sizeof(object))
#define xmalloc(n)   UTIL_malloc(n, __FILE__, __LINE__, __FUNCTION__)
#define xrealloc(m, n)   UTIL_realloc(m, n, __FILE__, __LINE__, __FUNCTION__)
#define xfree(m)   UTIL_free(m, __FILE__, __LINE__, __FUNCTION__)
#define xstrdup(m)   UTIL_strdup(m)
#define xstrndup(m, n)   UTIL_strndup(m, n)
#define xprintf(format,)   dbg_printf(FL_A, __FUNCTION__, format, __VA_ARGS__)
#define xvprintf(format,)   dbg_printf(FL_B, __FUNCTION__, format, __VA_ARGS__)
#define xpprintf(format,)   dbg_printf(FL_D, __FUNCTION__, format, __VA_ARGS__)
#define xeprintf(s)   (fprintf(stderr, s))
#define f_bit_set(fl_bit_vector, bit)   ((int)((fl_bit_vector)&(bit)))
#define urlchr_test(c)   (urlchr_table[(unsigned char)(c)] & 1)
#define DEBUG_LOG_FILE   "/var/log/spf.log"
#define OUTPUT_LOG_FILE   "/var/log/spflog.txt"
#define dbg_printf   dummy_debug

Functions

void _printf_dbg (const u_int8_t level, const char *function, const char *format,...)
void dummy_debug (const u_int8_t level, const char *function, const char *format,...)
void * UTIL_malloc (const int32_t, const char *, const int32_t, const char *)
void * UTIL_realloc (void *, const int32_t, const char *, const int32_t, const char *)
void UTIL_free (void *, const char *, const int32_t, const char *)
char * UTIL_printf (char *format,...)
void UTIL_log_result (peer_info_t *peer_info)
char * UTIL_get_date (void)
char * UTIL_strndup (const char *s, const size_t n)
char * UTIL_strdup (const char *s)
int16_t UTIL_index (const char *s, const char c)
char * UTIL_split_str (const char *s, const char c, const u_int8_t num)
char * UTIL_split_strr (const char *s, const char c, const u_int8_t num)
u_int8_t UTIL_count_delim (const char *s, const char c)
size_t UTIL_guess_whats_in_the_box (char *s, const char c, const u_int16_t num)
SPF_BOOL UTIL_is_spf_delim (const char c)
SPF_BOOL UTIL_is_spf_result (const char c)
SPF_BOOL UTIL_is_macro (const char *s)
SPF_BOOL UTIL_mx_cmp (peer_info_t *peer_info, const char *s, const int8_t cidr)
SPF_BOOL UTIL_a_cmp (peer_info_t *peer_info, const char *s, const int8_t cidr)
SPF_BOOL UTIL_ptr_cmp (peer_info_t *peer_info, const char *s)
SPF_MECHANISM UTIL_get_policy_mech (const char *s)
SPF_RESULT UTIL_get_mech_prefix (peer_info_t *peer_info, const char *s)
SPF_BOOL UTIL_assoc_prefix (peer_info_t *peer_info, SPF_RESULT p, const char *s)
policy_addr_tUTIL_expand_ip (const char *s)
char * UTIL_rev_addr (const char *s)
char * UTIL_get_dname (const char *s)
SPF_BOOL UTIL_cidr_cmp (peer_info_t *peer_info, const policy_addr_t *policy_addr, const struct in_addr *peer_addr)
SPF_BOOL UTIL_validate_ptr (peer_info_t *peer_info)
SPF_BOOL UTIL_validate_hostname (peer_info_t *peer_info, const char *s, const int8_t cidr)
char * UTIL_url_encode (const char *s)
char * UTIL_reverse (const char *s, const char delim)
SPF_BOOL UTIL_addnode (split_str_t *master, const char *s, SPF_BOOL last)

Variables

const u_char urlchr_table [256]


Define Documentation

#define _UTIL_H   1
 

Definition at line 46 of file util.h.

#define dbg_printf   dummy_debug
 

Definition at line 130 of file util.h.

#define DEBUG_LOG_FILE   "/var/log/spf.log"
 

Definition at line 120 of file util.h.

Referenced by _printf_dbg().

#define f_bit_set fl_bit_vector,
bit   )     ((int)((fl_bit_vector)&(bit)))
 

Definition at line 85 of file util.h.

Referenced by _printf_dbg().

#define OUTPUT_LOG_FILE   "/var/log/spflog.txt"
 

Definition at line 123 of file util.h.

Referenced by UTIL_log_result().

#define SIZEOF object   )     ((size_t) sizeof(object))
 

Definition at line 69 of file util.h.

Referenced by _printf_dbg().

#define urlchr_test  )     (urlchr_table[(unsigned char)(c)] & 1)
 

Definition at line 88 of file util.h.

Referenced by UTIL_url_encode().

#define xeprintf  )     (fprintf(stderr, s))
 

Definition at line 82 of file util.h.

Referenced by DNS_cname_answer(), DNS_mx_answer(), DNS_ptr_answer(), DNS_query(), DNS_txt_answer(), MACRO_addbuf(), MACRO_eatmore(), MACRO_expand(), MACRO_process(), SPF_close(), SPF_init(), SPF_parse_policy(), SPF_policy_main_rec(), UTIL_a_cmp(), UTIL_addnode(), UTIL_cidr_cmp(), UTIL_count_delim(), UTIL_expand_ip(), UTIL_get_dname(), UTIL_get_mech_prefix(), UTIL_get_policy_mech(), UTIL_guess_whats_in_the_box(), UTIL_index(), UTIL_is_macro(), UTIL_mx_cmp(), UTIL_ptr_cmp(), UTIL_rev_addr(), UTIL_reverse(), UTIL_split_str(), UTIL_split_strr(), UTIL_strdup(), UTIL_strndup(), UTIL_url_encode(), and UTIL_validate_hostname().

#define xfree  )     UTIL_free(m, __FILE__, __LINE__, __FUNCTION__)
 

Definition at line 74 of file util.h.

Referenced by DNS_ptr_answer(), DNS_txt_answer(), MACRO_eatmore(), MACRO_expand(), MACRO_process(), SPF_close(), SPF_init(), SPF_parse_policy(), SPF_policy_main_rec(), SPF_smtp_from(), SPF_smtp_helo(), UTIL_a_cmp(), UTIL_cidr_cmp(), UTIL_expand_ip(), UTIL_mx_cmp(), UTIL_ptr_cmp(), UTIL_rev_addr(), UTIL_reverse(), UTIL_split_str(), UTIL_split_strr(), UTIL_validate_hostname(), and UTIL_validate_ptr().

#define xmalloc  )     UTIL_malloc(n, __FILE__, __LINE__, __FUNCTION__)
 

Definition at line 72 of file util.h.

Referenced by DNS_cname_answer(), DNS_mx_answer(), DNS_txt_answer(), MACRO_addbuf(), MACRO_eatmore(), MACRO_expand(), MACRO_process(), SPF_build_header(), SPF_init(), SPF_result(), UTIL_a_cmp(), UTIL_addnode(), UTIL_expand_ip(), UTIL_rev_addr(), UTIL_reverse(), UTIL_strndup(), UTIL_url_encode(), and UTIL_validate_hostname().

#define xpprintf format   )     dbg_printf(FL_D, __FUNCTION__, format, __VA_ARGS__)
 

Definition at line 81 of file util.h.

#define xprintf format   )     dbg_printf(FL_A, __FUNCTION__, format, __VA_ARGS__)
 

Definition at line 79 of file util.h.

Referenced by DNS_mx_answer(), DNS_ptr_answer(), MACRO_eatmore(), MACRO_expand(), MACRO_process(), SPF_get_explain(), SPF_init(), SPF_parse_policy(), SPF_policy_main_rec(), SPF_result(), SPF_smtp_from(), and SPF_smtp_helo().

#define xrealloc m,
 )     UTIL_realloc(m, n, __FILE__, __LINE__, __FUNCTION__)
 

Definition at line 73 of file util.h.

Referenced by DNS_cname_answer(), DNS_mx_answer(), and DNS_txt_answer().

#define xstrdup  )     UTIL_strdup(m)
 

Definition at line 75 of file util.h.

Referenced by SPF_smtp_from(), and SPF_smtp_helo().

#define xstrndup m,
 )     UTIL_strndup(m, n)
 

Definition at line 76 of file util.h.

Referenced by DNS_ptr_answer(), DNS_txt_answer(), MACRO_eatmore(), MACRO_expand(), MACRO_process(), SPF_init(), SPF_parse_policy(), UTIL_a_cmp(), UTIL_cidr_cmp(), UTIL_expand_ip(), UTIL_get_dname(), UTIL_mx_cmp(), UTIL_ptr_cmp(), UTIL_rev_addr(), UTIL_reverse(), UTIL_split_str(), UTIL_split_strr(), UTIL_validate_hostname(), and UTIL_validate_ptr().

#define xvprintf format   )     dbg_printf(FL_B, __FUNCTION__, format, __VA_ARGS__)
 

Definition at line 80 of file util.h.

Referenced by DNS_cname_answer(), DNS_mx_answer(), DNS_ptr_answer(), DNS_query(), DNS_txt_answer(), MACRO_addbuf(), MACRO_eatmore(), MACRO_expand(), MACRO_process(), SPF_build_header(), SPF_init(), SPF_parse_policy(), SPF_policy_main_rec(), SPF_smtp_from(), UTIL_a_cmp(), UTIL_assoc_prefix(), UTIL_cidr_cmp(), UTIL_count_delim(), UTIL_expand_ip(), UTIL_free(), UTIL_get_dname(), UTIL_get_mech_prefix(), UTIL_get_policy_mech(), UTIL_guess_whats_in_the_box(), UTIL_index(), UTIL_is_macro(), UTIL_is_spf_delim(), UTIL_is_spf_result(), UTIL_malloc(), UTIL_mx_cmp(), UTIL_printf(), UTIL_ptr_cmp(), UTIL_realloc(), UTIL_rev_addr(), UTIL_reverse(), UTIL_split_str(), UTIL_split_strr(), UTIL_strdup(), UTIL_strndup(), UTIL_url_encode(), UTIL_validate_hostname(), and UTIL_validate_ptr().


Function Documentation

void _printf_dbg const u_int8_t  level,
const char *  function,
const char *  format,
  ...
 

Definition at line 61 of file util.c.

References confg, DEBUG_LOG_FILE, f_bit_set, spf_config_s::level, MAX_DEBUG_LEN, and SIZEOF.

void dummy_debug const u_int8_t  level,
const char *  function,
const char *  format,
  ...
 

Definition at line 106 of file util.c.

SPF_BOOL UTIL_a_cmp peer_info_t peer_info,
const char *  s,
const int8_t  cidr
 

Definition at line 791 of file util.c.

References peer_info_s::addr, policy_addr_s::addr, policy_addr_s::cidr, peer_info_s::cur_dom, FALSE, SPF_BOOL, SPF_PASS, TRUE, UTIL_assoc_prefix(), UTIL_cidr_cmp(), UTIL_index(), xeprintf, xfree, xmalloc, xstrndup, and xvprintf.

Referenced by SPF_parse_policy().

SPF_BOOL UTIL_addnode split_str_t master,
const char *  s,
SPF_BOOL  last
 

Definition at line 2020 of file util.c.

References split_str_s::elements, FALSE, split_str_s::head, split_str_node_s::len, split_str_node_s::next, split_str_node_s::s, SPF_BOOL, split_str_s::tail, TRUE, xeprintf, and xmalloc.

Referenced by UTIL_reverse().

SPF_BOOL UTIL_assoc_prefix peer_info_t peer_info,
SPF_RESULT  p,
const char *  s
 

Definition at line 1076 of file util.c.

References peer_info_s::error, FALSE, peer_info_s::last_m, MAX_ERROR, peer_info_s::RES, peer_info_s::rs, spf_result_t::s, SPF_BOOL, SPF_ERROR, SPF_H_FAIL, SPF_NEUTRAL, SPF_NONE, SPF_PASS, peer_info_s::spf_result, spf_rlevel, SPF_S_FAIL, SPF_UNKNOWN, SPF_UNMECH, TRUE, UTIL_index(), and xvprintf.

Referenced by DNS_query(), SPF_init(), SPF_parse_policy(), SPF_policy_main_rec(), UTIL_a_cmp(), UTIL_mx_cmp(), and UTIL_validate_hostname().

SPF_BOOL UTIL_cidr_cmp peer_info_t peer_info,
const policy_addr_t policy_addr,
const struct in_addr *  peer_addr
 

Definition at line 1604 of file util.c.

References policy_addr_s::addr, policy_addr_s::cidr, FALSE, IP_ADDR, SPF_BOOL, TRUE, xeprintf, xfree, xstrndup, and xvprintf.

Referenced by SPF_parse_policy(), UTIL_a_cmp(), and UTIL_validate_hostname().

u_int8_t UTIL_count_delim const char *  s,
const char  c
 

Definition at line 541 of file util.c.

References xeprintf, and xvprintf.

Referenced by MACRO_eatmore(), and UTIL_get_dname().

policy_addr_t* UTIL_expand_ip const char *  s  ) 
 

Definition at line 1365 of file util.c.

References policy_addr_s::addr, policy_addr_s::cidr, UTIL_index(), xeprintf, xfree, xmalloc, xstrndup, and xvprintf.

Referenced by SPF_parse_policy().

void UTIL_free void *  ,
const char *  ,
const  int32_t,
const char * 
 

Definition at line 358 of file util.c.

References xvprintf.

char* UTIL_get_date void   ) 
 

Definition at line 153 of file util.c.

Referenced by UTIL_log_result().

char* UTIL_get_dname const char *  s  ) 
 

Definition at line 1557 of file util.c.

References UTIL_count_delim(), UTIL_split_str(), xeprintf, xstrndup, and xvprintf.

Referenced by DNS_ptr_answer().

SPF_RESULT UTIL_get_mech_prefix peer_info_t peer_info,
const char *  s
 

Definition at line 1262 of file util.c.

References peer_info_s::ALL, peer_info_s::last_m, peer_info_s::RES_P, SPF_ERROR, SPF_H_FAIL, SPF_NEUTRAL, SPF_PASS, SPF_RESULT, spf_rlevel, SPF_S_FAIL, TRUE, UTIL_index(), xeprintf, and xvprintf.

Referenced by SPF_parse_policy().

SPF_MECHANISM UTIL_get_policy_mech const char *  s  ) 
 

Definition at line 980 of file util.c.

References A, ALL, DEFAULT, EXISTS, EXPLAIN, INCLUDE, IP4, IP6, MX, NO_POLICY, PTR, REDIRECT, SPF_MECHANISM, UNMECH, VERSION, xeprintf, and xvprintf.

Referenced by SPF_parse_policy().

size_t UTIL_guess_whats_in_the_box char *  s,
const char  c,
const u_int16_t  num
 

Definition at line 580 of file util.c.

References xeprintf, and xvprintf.

int16_t UTIL_index const char *  s,
const char  c
 

Definition at line 387 of file util.c.

References xeprintf, and xvprintf.

Referenced by MACRO_expand(), SPF_parse_policy(), UTIL_a_cmp(), UTIL_assoc_prefix(), UTIL_expand_ip(), and UTIL_get_mech_prefix().

SPF_BOOL UTIL_is_macro const char *  s  ) 
 

Definition at line 687 of file util.c.

References FALSE, SPF_BOOL, TRUE, xeprintf, and xvprintf.

Referenced by SPF_parse_policy().

SPF_BOOL UTIL_is_spf_delim const char  c  ) 
 

Definition at line 635 of file util.c.

References FALSE, SPF_BOOL, TRUE, and xvprintf.

Referenced by MACRO_eatmore().

SPF_BOOL UTIL_is_spf_result const char  c  ) 
 

Definition at line 661 of file util.c.

References FALSE, SPF_BOOL, TRUE, and xvprintf.

Referenced by SPF_parse_policy().

void UTIL_log_result peer_info_t peer_info  ) 
 

Definition at line 180 of file util.c.

References peer_info_s::error, peer_info_s::from, MAX_DEBUG_LEN, OUTPUT_LOG_FILE, peer_info_s::r_ip, peer_info_s::RES, peer_info_s::spf_result, spf_rlevel, peer_info_s::spf_ver, SPF_VERSION, and UTIL_get_date().

Referenced by SPF_policy_main_rec().

void* UTIL_malloc const  int32_t,
const char *  ,
const  int32_t,
const char * 
 

Definition at line 290 of file util.c.

References xvprintf.

Referenced by UTIL_realloc().

SPF_BOOL UTIL_mx_cmp peer_info_t peer_info,
const char *  s,
const int8_t  cidr
 

Definition at line 728 of file util.c.

References peer_info_s::addr, DNS_query(), FALSE, peer_info_s::from, SPF_BOOL, SPF_PASS, TRUE, UTIL_assoc_prefix(), UTIL_validate_hostname(), xeprintf, xfree, xstrndup, and xvprintf.

Referenced by SPF_parse_policy().

char* UTIL_printf char *  format,
  ...
 

Definition at line 127 of file util.c.

References xvprintf.

SPF_BOOL UTIL_ptr_cmp peer_info_t peer_info,
const char *  s
 

Definition at line 923 of file util.c.

References peer_info_s::cur_dom, DNS_query(), peer_info_s::error, FALSE, peer_info_s::r_ip, peer_info_s::rs, SPF_BOOL, TRUE, UTIL_rev_addr(), xeprintf, xfree, xstrndup, and xvprintf.

Referenced by SPF_parse_policy().

void* UTIL_realloc void *  ,
const  int32_t,
const char *  ,
const  int32_t,
const char * 
 

Definition at line 321 of file util.c.

References UTIL_malloc(), and xvprintf.

char* UTIL_rev_addr const char *  s  ) 
 

Definition at line 1498 of file util.c.

References xeprintf, xfree, xmalloc, xstrndup, and xvprintf.

Referenced by UTIL_ptr_cmp(), and UTIL_validate_ptr().

char* UTIL_reverse const char *  s,
const char  delim
 

Definition at line 1933 of file util.c.

References split_str_s::elements, FALSE, split_str_s::head, split_str_node_s::len, split_str_node_s::next, split_str_node_s::s, split_str_s::tail, TRUE, UTIL_addnode(), xeprintf, xfree, xmalloc, xstrndup, and xvprintf.

Referenced by MACRO_eatmore().

char* UTIL_split_str const char *  s,
const char  c,
const u_int8_t  num
 

Definition at line 425 of file util.c.

References xeprintf, xfree, xstrndup, and xvprintf.

Referenced by UTIL_get_dname().

char* UTIL_split_strr const char *  s,
const char  c,
const u_int8_t  num
 

Definition at line 475 of file util.c.

References xeprintf, xfree, xstrndup, and xvprintf.

Referenced by MACRO_eatmore().

char* UTIL_strdup const char *  s  ) 
 

Definition at line 257 of file util.c.

References FALSE, xeprintf, and xvprintf.

char* UTIL_strndup const char *  s,
const size_t  n
 

Definition at line 221 of file util.c.

References FALSE, xeprintf, xmalloc, and xvprintf.

char* UTIL_url_encode const char *  s  ) 
 

Definition at line 1881 of file util.c.

References urlchr_test, xeprintf, xmalloc, and xvprintf.

SPF_BOOL UTIL_validate_hostname peer_info_t peer_info,
const char *  s,
const int8_t  cidr
 

Definition at line 1719 of file util.c.

References policy_addr_s::addr, peer_info_s::addr, policy_addr_s::cidr, FALSE, IP_ADDR, peer_info_s::r_ip, SPF_BOOL, SPF_PASS, TRUE, UTIL_assoc_prefix(), UTIL_cidr_cmp(), xeprintf, xfree, xmalloc, xstrndup, and xvprintf.

Referenced by DNS_ptr_answer(), and UTIL_mx_cmp().

SPF_BOOL UTIL_validate_ptr peer_info_t peer_info  ) 
 

Definition at line 1673 of file util.c.

References peer_info_s::cur_dom, DNS_query(), peer_info_s::error, FALSE, peer_info_s::r_ip, peer_info_s::r_vhname, peer_info_s::rs, SPF_BOOL, TRUE, UTIL_rev_addr(), xfree, xstrndup, and xvprintf.

Referenced by MACRO_process().


Variable Documentation

const u_char urlchr_table[256] [static]
 

Initial value:

{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }

Definition at line 89 of file util.h.


Generated on Thu Jul 1 14:05:44 2004 for libspf v1.0 by doxygen 1.3.7