From ee0064532cba22668bca2e1d4b42c1aa258e3552 Mon Sep 17 00:00:00 2001 From: Tim Ruehsen Date: Thu, 17 Apr 2014 12:31:06 +0200 Subject: [PATCH] added psl_builtin_filename() --- docs/libpsl/libpsl-sections.txt | 1 + include/libpsl.h | 5 ++++- src/psl.c | 17 ++++++++++++++++- src/psl2c.c | 6 ++++-- tools/psl.c | 1 + 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/libpsl/libpsl-sections.txt b/docs/libpsl/libpsl-sections.txt index 19f6599..c6eaa16 100644 --- a/docs/libpsl/libpsl-sections.txt +++ b/docs/libpsl/libpsl-sections.txt @@ -14,5 +14,6 @@ psl_suffix_exception_count psl_builtin_compile_time psl_builtin_file_time psl_builtin_sha1sum +psl_builtin_filename psl_is_cookie_domain_acceptable diff --git a/include/libpsl.h b/include/libpsl.h index 9d4f8db..4ce408c 100644 --- a/include/libpsl.h +++ b/include/libpsl.h @@ -73,9 +73,12 @@ time_t // returns mtime of PSL source file time_t psl_builtin_file_time(void); -// returns MD5 checksum (hex-encoded, lowercase) of PSL source file +// returns SHA1 checksum (hex-encoded, lowercase) of PSL source file const char * psl_builtin_sha1sum(void); +// returns file name of PSL source file +const char * + psl_builtin_filename(void); #ifdef __cplusplus diff --git a/src/psl.c b/src/psl.c index fd9f7fb..d96fd7f 100644 --- a/src/psl.c +++ b/src/psl.c @@ -618,7 +618,6 @@ time_t psl_builtin_file_time(void) return _psl_file_time; } -// returns MD5 checksum (hex-encoded, lowercase) of PSL source file /** * psl_builtin_sha1sum: * @@ -636,6 +635,22 @@ const char *psl_builtin_sha1sum(void) return _psl_sha1_checksum; } +/** + * psl_builtin_filename: + * + * This function returns the file name of the Publix Suffix List file that has been built in. + * + * If the generation of built-in data has been disabled during compilation, an empty string will be returned. + * + * Returns: String containing the PSL file name or an empty string. + * + * Since: 0.1 + */ +const char *psl_builtin_filename(void) +{ + return _psl_filename; +} + /** * psl_is_cookie_domain_acceptable: * @psl: PSL context pointer diff --git a/src/psl2c.c b/src/psl2c.c index c5bf12f..e55301c 100644 --- a/src/psl2c.c +++ b/src/psl2c.c @@ -380,7 +380,8 @@ int main(int argc, const char **argv) st.st_mtime = 0; fprintf(fpout, "static time_t _psl_file_time = %lu;\n", st.st_mtime); fprintf(fpout, "static time_t _psl_compile_time = %lu;\n", time(NULL)); - fprintf(fpout, "static char _psl_sha1_checksum[] = \"%s\";\n", checksum); + fprintf(fpout, "static const char _psl_sha1_checksum[] = \"%s\";\n", checksum); + fprintf(fpout, "static const char _psl_filename[] = \"%s\";\n", checksum); if (fclose(fpout) != 0) ret = 4; @@ -396,7 +397,8 @@ int main(int argc, const char **argv) fprintf(fpout, "static _psl_entry_t suffix_exceptions[0];\n"); fprintf(fpout, "static time_t _psl_file_time;\n"); fprintf(fpout, "static time_t _psl_compile_time;\n"); - fprintf(fpout, "static char _psl_sha1_checksum[]= \"\";\n"); + fprintf(fpout, "static const char _psl_sha1_checksum[] = \"\";\n"); + fprintf(fpout, "static const char _psl_filename[] = \"\";\n"); if (fclose(fpout) != 0) ret = 4; diff --git a/tools/psl.c b/tools/psl.c index 50ddb56..0e8c926 100644 --- a/tools/psl.c +++ b/tools/psl.c @@ -142,6 +142,7 @@ int main(int argc, const char *const *argv) if (psl) { printf("builtin suffixes: %d\n", psl_suffix_count(psl)); printf("builtin exceptions: %d\n", psl_suffix_exception_count(psl)); + printf("builtin filename: %s\n", psl_builtin_filename()); printf("builtin compile time: %ld (%s)\n", psl_builtin_compile_time(), time2str(psl_builtin_compile_time())); printf("builtin file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time())); printf("builtin SHA1 file hash: %s\n", psl_builtin_sha1sum());