| 342 | |
| 343 | |
| 344 | void hcache_done() |
| 345 | { |
| 346 | FILE * f; |
| 347 | HCACHEDATA * c; |
| 348 | int header_count = 0; |
| 349 | const char * hcachename; |
| 350 | int maxage; |
| 351 | |
| 352 | if ( !hcachehash ) |
| 353 | return; |
| 354 | |
| 355 | if ( !( hcachename = cache_name() ) ) |
| 356 | goto cleanup; |
| 357 | |
| 358 | if ( !( f = fopen( hcachename, "wb" ) ) ) |
| 359 | goto cleanup; |
| 360 | |
| 361 | maxage = cache_maxage(); |
| 362 | |
| 363 | /* Print out the version. */ |
| 364 | write_netstring( f, CACHE_FILE_VERSION ); |
| 365 | |
| 366 | c = hcachelist; |
| 367 | for ( c = hcachelist; c; c = c->next ) |
| 368 | { |
| 369 | LISTITER iter; |
| 370 | LISTITER end; |
| 371 | char time_secs_str[ 30 ]; |
| 372 | char time_nsecs_str[ 30 ]; |
| 373 | char age_str[ 30 ]; |
| 374 | char includes_count_str[ 30 ]; |
| 375 | char hdrscan_count_str[ 30 ]; |
| 376 | |
| 377 | if ( maxage == 0 ) |
| 378 | c->age = 0; |
| 379 | else if ( c->age > maxage ) |
| 380 | continue; |
| 381 | |
| 382 | sprintf( includes_count_str, "%lu", (long unsigned)list_length( |
| 383 | c->includes ) ); |
| 384 | sprintf( hdrscan_count_str, "%lu", (long unsigned)list_length( |
| 385 | c->hdrscan ) ); |
| 386 | sprintf( time_secs_str, "%lu", (long unsigned)c->time.secs ); |
| 387 | sprintf( time_nsecs_str, "%lu", (long unsigned)c->time.nsecs ); |
| 388 | sprintf( age_str, "%lu", (long unsigned)c->age ); |
| 389 | |
| 390 | write_netstring( f, CACHE_RECORD_HEADER ); |
| 391 | write_netstring( f, object_str( c->boundname ) ); |
| 392 | write_netstring( f, time_secs_str ); |
| 393 | write_netstring( f, time_nsecs_str ); |
| 394 | write_netstring( f, age_str ); |
| 395 | write_netstring( f, includes_count_str ); |
| 396 | for ( iter = list_begin( c->includes ), end = list_end( c->includes ); |
| 397 | iter != end; iter = list_next( iter ) ) |
| 398 | write_netstring( f, object_str( list_item( iter ) ) ); |
| 399 | write_netstring( f, hdrscan_count_str ); |
| 400 | for ( iter = list_begin( c->hdrscan ), end = list_end( c->hdrscan ); |
| 401 | iter != end; iter = list_next( iter ) ) |
no test coverage detected