| 180 | |
| 181 | |
| 182 | void hcache_init() |
| 183 | { |
| 184 | FILE * f; |
| 185 | OBJECT * version = 0; |
| 186 | int header_count = 0; |
| 187 | const char * hcachename; |
| 188 | |
| 189 | if ( hcachehash ) |
| 190 | return; |
| 191 | |
| 192 | hcachehash = hashinit( sizeof( HCACHEDATA ), "hcache" ); |
| 193 | |
| 194 | if ( !( hcachename = cache_name() ) ) |
| 195 | return; |
| 196 | |
| 197 | if ( !( f = fopen( hcachename, "rb" ) ) ) |
| 198 | { |
| 199 | if ( errno != ENOENT ) |
| 200 | err_printf( "[errno %d] failed to read hcache file '%s': %s", |
| 201 | errno, hcachename, strerror(errno) ); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | version = read_netstring( f ); |
| 206 | |
| 207 | if ( !version || strcmp( object_str( version ), CACHE_FILE_VERSION ) ) |
| 208 | goto bail; |
| 209 | |
| 210 | while ( 1 ) |
| 211 | { |
| 212 | HCACHEDATA cachedata; |
| 213 | HCACHEDATA * c; |
| 214 | OBJECT * record_type = 0; |
| 215 | OBJECT * time_secs_str = 0; |
| 216 | OBJECT * time_nsecs_str = 0; |
| 217 | OBJECT * age_str = 0; |
| 218 | OBJECT * includes_count_str = 0; |
| 219 | OBJECT * hdrscan_count_str = 0; |
| 220 | int i; |
| 221 | int count; |
| 222 | LIST * l; |
| 223 | int found; |
| 224 | |
| 225 | cachedata.boundname = 0; |
| 226 | cachedata.includes = 0; |
| 227 | cachedata.hdrscan = 0; |
| 228 | |
| 229 | record_type = read_netstring( f ); |
| 230 | if ( !record_type ) |
| 231 | { |
| 232 | err_printf( "invalid %s\n", hcachename ); |
| 233 | goto cleanup; |
| 234 | } |
| 235 | if ( !strcmp( object_str( record_type ), CACHE_RECORD_END ) ) |
| 236 | { |
| 237 | object_free( record_type ); |
| 238 | break; |
| 239 | } |
no test coverage detected