util.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
#ifndef _UTIL_H
00047 #define _UTIL_H 1
00048 
00049 
#include "../../config.h"    
00050 
#include <stdio.h>           
00051 
#include <stdlib.h>          
00052 
#include <stdarg.h>          
00053 
#include <string.h>          
00054 
#include <strings.h>         
00055 
#include <unistd.h>          
00056 
#include <sys/socket.h>      
00057 
#include <netinet/in.h>      
00058 
#include <time.h>            
00059 
#include <ctype.h>           
00060 
00061 
#ifdef _WITH_SOLARIS
00062 
#include <link.h>            
00063 
#elif defined(__FreeBSD__)
00064 
#include <inttypes.h>        
00065 
#else
00066 
#include <stdint.h>          
00067 
#endif 
00068 
00069 
#ifdef _HAVE_INTTYPES_H
00070 
#include <inttypes.h>
00071 
#endif 
00072 
00073 
#include "main.h"            
00074 
00075 
#ifdef _WITH_PTHREADS
00076 
#include "dns.h"             
00077 
#endif 
00078 
00079 
#ifdef  HAVE__BEGIN_DECLS
00080 
__BEGIN_DECLS
00081 
#else
00082 
# ifdef __cplusplus
00083 
extern "C" {
00084 
# endif 
00085 
#endif 
00086 
00087 
00088 
00089  
00090 
00091 
00092 
00093 
00094 
00095 #define SPF_MAX_DATETIME 26
00096 
00097 
00098 #define SPF_MAX_GHBNR_DBUF 2048
00099 
00100 
00101  
00102 
00103 
00104 
00105 
00106 
00107 
00108 #define SIZEOF(object)  ((size_t) sizeof(object))
00109 
00110 
00111 
#ifndef HAVE___FUNCTION__
00112 
# ifdef HAVE___FUNC__
00113 
#  define __FUNCTION__  __func__
00114 
# else
00115 
#  define __FUNCTION__  "?"
00116 
# endif 
00117 
#endif 
00118 
00119 
00120  
00121 
00122 
00123 
00124 
00125 #define xmalloc(n)      UTIL_malloc(n, __FILE__, __LINE__, __FUNCTION__)
00126 #define xrealloc(m, n)  UTIL_realloc(m, n, __FILE__, __LINE__, __FUNCTION__)
00127 #define xfree(m)        UTIL_free(m, __FILE__, __LINE__, __FUNCTION__)
00128 #define xstrdup(m)      UTIL_strdup(m)
00129 #define xstrndup(m, n)  UTIL_strndup(m, n)
00130 
00131 
00132  
00133 
00134 
00135 
00136 
00137 
00138 #define xprintf(format,...) \
00139 
  dbg_printf(FL_A, __FUNCTION__, __FILE__, __LINE__, format, __VA_ARGS__)
00140 
00141 
00142 #define xvprintf(format,...) \
00143 
  dbg_printf(FL_B, __FUNCTION__, __FILE__, __LINE__, format, __VA_ARGS__)
00144 
00145 
00146 #define xpprintf(s) \
00147 
  dbg_pprintf(FL_D, __FUNCTION__, __FILE__, __LINE__, s) 
00148 
00149 
00150 #define xeprintf(format,...) \
00151 
  dbg_printf(FL_E, __FUNCTION__, __FILE__, __LINE__, format, __VA_ARGS__)
00152 
00153 
00154 #define xepprintf(s)  \
00155 
  dbg_pprintf(FL_F, __FUNCTION__, __FILE__, __LINE__, s)
00156 
00157 
00158  
00159 
00160 
00161 
00162 
00163 #define xpthread_mutex_lock(m)   _UTIL_pthread_mutex(m, SPF_TRUE)
00164 #define xpthread_mutex_unlock(m) _UTIL_pthread_mutex(m, SPF_FALSE)
00165 
00166 
00167 
00168 #define f_bit_set(fl_bit_vector, bit) ((int)((fl_bit_vector)&(bit)))
00169 
00170 
00171 #define urlchr_test(c) (urlchr_table[(unsigned char)(c)] & 1)
00172 static const u_char 
urlchr_table[256] =
00173 {
00174   1,  1,  1,  1,   1,  1,  1,  1,   
00175   1,  1,  1,  1,   1,  1,  1,  1,   
00176   1,  1,  1,  1,   1,  1,  1,  1,   
00177   1,  1,  1,  1,   1,  1,  1,  1,   
00178   1,  0,  1,  1,   0,  1,  1,  0,   
00179   0,  0,  0,  1,   0,  0,  0,  1,   
00180   0,  0,  0,  0,   0,  0,  0,  0,   
00181   0,  0,  1,  1,   1,  1,  1,  1,   
00182   1,  0,  0,  0,   0,  0,  0,  0,   
00183   0,  0,  0,  0,   0,  0,  0,  0,   
00184   0,  0,  0,  0,   0,  0,  0,  0,   
00185   0,  0,  0,  1,   1,  1,  1,  0,   
00186   1,  0,  0,  0,   0,  0,  0,  0,   
00187   0,  0,  0,  0,   0,  0,  0,  0,   
00188   0,  0,  0,  0,   0,  0,  0,  0,   
00189   0,  0,  0,  1,   1,  1,  1,  1,   
00190 
00191   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00192   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00193   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00194   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00195 
00196   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00197   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00198   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00199   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00200 };
00201 
00202 
00203 
00204  
00205 
00206 
00207 
00208 
00209 
00210 #define DEBUG_LOG_FILE "/var/log/spf.log"
00211 
00212 
00213 #define OUTPUT_LOG_FILE "/var/log/spflog.txt"
00214 
00215 
#if defined _SPF_DEBUG
00216 
#define dbg_printf _printf_dbg
00217 
#define dbg_pprintf _pprintf_dbg
00218 
#endif
00219 
00220 
#ifndef _SPF_DEBUG
00221 #define dbg_printf _dummy_debug
00222 #define dbg_pprintf _dummy_pdebug
00223 
#endif
00224 
00225 
00226 
00227  
00228 
00229 
00230 
00231 
00232 
00233  
00234 
00235 
00236 
00237 
void _printf_dbg(
const u_int8_t, 
const char *, 
const char *, 
const size_t, 
00238   
const char *, ...);
00239 
00240 
void _pprintf_dbg(
const u_int8_t, 
const char *, 
const char *, 
const size_t,
00241   
const char *);
00242 
00243 
void _dummy_debug(
const u_int8_t, 
const char *, 
const char *, 
const size_t,
00244   
const char *, ...);
00245 
00246 
void _dummy_pdebug(
const u_int8_t, 
const char *, 
const char *, 
const size_t,
00247   
const char *);
00248 
00249 
00250  
00251 
00252 
00253 
00254 
00255 
void *
UTIL_malloc(
const int32_t, 
const char *, 
const int32_t, 
const char *);
00256 
void *
UTIL_realloc(
void *, 
const int32_t, 
const char *, 
const int32_t, 
const char *);
00257 
void  UTIL_free(
void *, 
const char *, 
const int32_t, 
const char *);
00258 
00259 
00260  
00261 
00262 
00263 
00264 
00265 
void      UTIL_log_result(
peer_info_t *);
00266 
char     *
UTIL_get_date(
void);
00267 
char     *
UTIL_strndup(
const char *, 
const size_t);
00268 
char     *
UTIL_strdup(
const char *);
00269 int16_t   
UTIL_index(
const char *, 
const char);
00270 
char     *
UTIL_split_str(
const char *, 
const char, 
const u_int8_t);
00271 
char     *
UTIL_split_strr(
const char *, 
const char, 
const u_int8_t);
00272 u_int8_t  
UTIL_count_delim(
const char *, 
const char);
00273 
SPF_BOOL  UTIL_is_spf_delim(
const char);
00274 
SPF_BOOL  UTIL_is_spf_result(
const char);
00275 
SPF_BOOL  UTIL_is_macro(
const char *);
00276 
00277 
00278  
00279 
00280 
00281 
00282 
00283 
SPF_BOOL  UTIL_mx_cmp(
peer_info_t *, 
const char *, 
const int8_t);
00284 
SPF_BOOL  UTIL_a_cmp(
peer_info_t *, 
const char *, 
const int8_t);
00285 
SPF_BOOL  UTIL_ptr_cmp(
peer_info_t *, 
const char *);
00286 
00287 
00288  
00289 
00290 
00291 
00292 
00293 
SPF_MECHANISM UTIL_get_policy_mech(
const char *);
00294 
SPF_RESULT    UTIL_get_mech_prefix(
peer_info_t *, 
const char *);
00295 
SPF_BOOL      UTIL_assoc_prefix(
peer_info_t *, 
SPF_RESULT, 
const char *);
00296 
policy_addr_t *
UTIL_expand_ip(
const char *);
00297 
SPF_BOOL      UTIL_is_spf_delim(
const char );
00298 
SPF_BOOL      UTIL_is_ip(
const char *);
00299 
00300 
00301  
00302 
00303 
00304 
00305 
00306 
char     *
UTIL_rev_addr(
const char *);
00307 
char     *
UTIL_get_dname(
const char *);
00308 
SPF_BOOL  UTIL_cidr_cmp(
const policy_addr_t *, 
const struct in_addr *);
00309 
SPF_BOOL  UTIL_validate_ptr(
peer_info_t *);
00310 
SPF_BOOL  UTIL_validate_hostname(
peer_info_t *, 
const char *, 
const int8_t);
00311 
char     *
UTIL_url_encode(
const char *);
00312 
char     *
UTIL_reverse(
const char *, 
const char);
00313 
SPF_BOOL  UTIL_addnode(
split_str_t *, 
const char *, 
SPF_BOOL);
00314 
00315 
00316  
00317 
00318 
00319 
00320 
00321 
void _UTIL_pthread_mutex(
void *, 
SPF_BOOL);
00322 
00323 
00324 
#ifdef _WITH_PTHREADS
00325 
00326 
00327 
extern pthread_mutex_t 
util_mutex;
00328 
00329 
#else
00330 
00331 
00332 
extern void *
util_mutex; 
00333 
00334 
#endif 
00335 
00336 
00337 
#ifdef  HAVE__BEGIN_DECLS
00338 
__END_DECLS 
00339 
#else
00340 
# ifdef __cplusplus
00341 
}
00342 
# endif 
00343 
#endif 
00344 
00345 
#endif 
00346 
00347 
Generated on Thu Sep 16 18:10:47 2004 for libSPF v1.0 by
 1.3.8
 1.3.8