Add new function psl_builtin_outdated()

This commit is contained in:
Tim Rühsen 2015-09-19 14:00:49 +02:00
parent 34289fa59b
commit 6a8f33ee39
3 changed files with 31 additions and 1 deletions

View File

@ -16,6 +16,7 @@ psl_builtin_compile_time
psl_builtin_file_time
psl_builtin_sha1sum
psl_builtin_filename
psl_builtin_outdated
psl_is_cookie_domain_acceptable
psl_get_version
psl_str_to_utf8lower

View File

@ -113,7 +113,9 @@ const char *
/* returns library version */
const char *
psl_get_version(void);
/* returns wether the built-in data is outdated or not */
int
psl_builtin_outdated(void);
#ifdef __cplusplus
}

View File

@ -54,6 +54,9 @@
# define ngettext(STRING1,STRING2,N) STRING2
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -84,6 +87,7 @@
#endif
#include <libpsl.h>
#include <bits/stat.h>
/* number of elements within an array */
#define countof(a) (sizeof(a)/sizeof(*(a)))
@ -951,6 +955,29 @@ const char *psl_builtin_filename(void)
return _psl_filename;
}
/**
* psl_builtin_outdated:
*
* This function checks if the built-in data is older than the file it has been created from.
* If it is, it might be a good idea for the application to reload the PSL.
* The mtime is taken as reference.
*
* If the PSL file does not exist, it is assumed that the built-in data is not outdated.
*
* Returns: 1 if the built-in is outdated, 0 otherwise.
*
* Since: 0.10.0
*/
int psl_builtin_outdated(void)
{
struct stat st;
if (stat(_psl_filename, &st) == 0 && st.st_mtime > _psl_file_time)
return 0;
return 1;
}
/**
* psl_get_version:
*