diff --git a/docs/libpsl/libpsl-sections.txt b/docs/libpsl/libpsl-sections.txt index 4c73e47..2c43358 100644 --- a/docs/libpsl/libpsl-sections.txt +++ b/docs/libpsl/libpsl-sections.txt @@ -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 diff --git a/include/libpsl.h b/include/libpsl.h index c059198..aa223e4 100644 --- a/include/libpsl.h +++ b/include/libpsl.h @@ -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 } diff --git a/src/psl.c b/src/psl.c index d311778..6108aef 100644 --- a/src/psl.c +++ b/src/psl.c @@ -54,6 +54,9 @@ # define ngettext(STRING1,STRING2,N) STRING2 #endif +#include +#include +#include #include #include #include @@ -84,6 +87,7 @@ #endif #include +#include /* 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: *