libspf2 1.2.10
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of either: 00004 * 00005 * a) The GNU Lesser General Public License as published by the Free 00006 * Software Foundation; either version 2.1, or (at your option) any 00007 * later version, 00008 * 00009 * OR 00010 * 00011 * b) The two-clause BSD license. 00012 * 00013 * These licenses can be found with the distribution in the file LICENSES 00014 */ 00015 00016 00017 #include "spf_sys_config.h" 00018 00019 #ifdef STDC_HEADERS 00020 # include <stdlib.h> /* malloc / free */ 00021 # include <ctype.h> /* isupper / tolower */ 00022 #endif 00023 00024 #ifdef HAVE_MEMORY_H 00025 #include <memory.h> 00026 #endif 00027 00028 00029 00030 #include "spf.h" 00031 #include "spf_internal.h" 00032 00033 00037 void 00038 SPF_get_lib_version(int *major, int *minor, int *patch) 00039 { 00040 *major = SPF_LIB_VERSION_MAJOR; 00041 *minor = SPF_LIB_VERSION_MINOR; 00042 *patch = SPF_LIB_VERSION_PATCH; 00043 } 00044 00045 00046 00053 char * 00054 SPF_sanitize(SPF_server_t *spf_server, char *str) 00055 { 00056 char *p; 00057 00058 SPF_ASSERT_NOTNULL(spf_server); 00059 00060 if (! spf_server->sanitize) 00061 return str; 00062 00063 if (str == NULL) 00064 return str; 00065 00066 for (p = str; *p != '\0'; p++) 00067 if (! isprint( (unsigned char)*p )) 00068 *p = '?'; 00069 00070 return str; 00071 } 00072 00073 00074 00075 00076 00080 const char * 00081 SPF_strresult(SPF_result_t result) 00082 { 00083 switch (result) { 00084 case SPF_RESULT_INVALID: 00085 return "(invalid)"; 00086 break; 00087 00088 case SPF_RESULT_PASS: /* + */ 00089 return "pass"; 00090 break; 00091 00092 case SPF_RESULT_FAIL: /* - */ 00093 return "fail"; 00094 break; 00095 00096 case SPF_RESULT_SOFTFAIL: /* ~ */ 00097 return "softfail"; 00098 break; 00099 00100 case SPF_RESULT_NEUTRAL: /* ? */ 00101 return "neutral"; 00102 break; 00103 00104 case SPF_RESULT_PERMERROR: /* permanent error */ 00105 return "permerror"; 00106 break; 00107 00108 case SPF_RESULT_TEMPERROR: /* temporary error */ 00109 return "temperror"; 00110 break; 00111 00112 case SPF_RESULT_NONE: /* no SPF record found */ 00113 return "none"; 00114 break; 00115 00116 default: 00117 return "(error: unknown result)"; 00118 break; 00119 } 00120 } 00121 00122 00123 00127 const char * 00128 SPF_strreason(SPF_reason_t reason) 00129 { 00130 switch (reason) { 00131 case SPF_REASON_NONE: 00132 return "none"; 00133 break; 00134 00135 case SPF_REASON_LOCALHOST: 00136 return "localhost"; 00137 break; 00138 00139 case SPF_REASON_LOCAL_POLICY: 00140 return "local policy"; 00141 break; 00142 00143 case SPF_REASON_MECH: 00144 return "mechanism"; 00145 break; 00146 00147 case SPF_REASON_DEFAULT: 00148 return "default"; 00149 break; 00150 00151 case SPF_REASON_2MX: 00152 return "secondary MX"; 00153 break; 00154 00155 default: 00156 return "(invalid reason)"; 00157 break; 00158 00159 } 00160 } 00161 00162 const char * 00163 SPF_strrrtype(ns_type rr_type) 00164 { 00165 switch (rr_type) { 00166 case ns_t_a: return "A"; 00167 case ns_t_aaaa: return "AAAA"; 00168 case ns_t_any: return "ANY"; 00169 case ns_t_invalid: return "BAD"; 00170 case ns_t_mx: return "MX"; 00171 case ns_t_ptr: return "PTR"; 00172 case ns_t_spf: return "SPF"; 00173 case ns_t_txt: return "TXT"; 00174 default: return "??"; 00175 } 00176 } 00177 00187 SPF_errcode_t 00188 SPF_recalloc(char **bufp, size_t *buflenp, size_t buflen) 00189 { 00190 char *buf; 00191 00192 if (*buflenp < buflen) { 00193 if (buflen < 64) 00194 buflen = 64; 00195 buf = realloc(*bufp, buflen); 00196 if (buf == NULL) 00197 return SPF_E_NO_MEMORY; 00198 00199 // memset(buf + *buflenp, '\0', buflen - *buflenp); 00200 *bufp = buf; 00201 *buflenp = buflen; 00202 } 00203 else { 00204 SPF_ASSERT_NOTNULL(*bufp); 00205 } 00206 00207 memset(*bufp, '\0', *buflenp); 00208 return SPF_E_SUCCESS; 00209 }