added info functions
This commit is contained in:
parent
63fc945fff
commit
0771255742
|
@ -62,6 +62,16 @@ int
|
|||
int
|
||||
psl_inline_suffix_exception_count(void);
|
||||
|
||||
// returns compilation time
|
||||
time_t
|
||||
psl_inline_builtin_compile_time(void);
|
||||
// returns mtime of PSL source file
|
||||
time_t
|
||||
psl_inline_builtin_file_time(void);
|
||||
// returns MD5 checksum of PSL source file
|
||||
const char *
|
||||
psl_inline_builtin_md5sum(void);
|
||||
|
||||
PSL_END_DECLS
|
||||
|
||||
#endif /* _LIBPSL_LIBPSL_INLINE_H */
|
||||
|
|
|
@ -27,4 +27,4 @@ psl2c_LDADD = -lidn2
|
|||
|
||||
# Build rule for suffix.c
|
||||
suffixes.c: $(top_srcdir)/data/effective_tld_names.dat psl2c$(EXEEXT)
|
||||
./psl2c$(EXEEXT) <$(top_srcdir)/data/effective_tld_names.dat >suffixes.c
|
||||
./psl2c$(EXEEXT) $(top_srcdir)/data/effective_tld_names.dat suffixes.c
|
||||
|
|
|
@ -24,11 +24,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// need _GNU_SOURCE for qsort_r()
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
@ -151,3 +146,21 @@ int psl_inline_suffix_exception_count(void)
|
|||
{
|
||||
return countof(suffix_exceptions);
|
||||
}
|
||||
|
||||
// returns compilation time
|
||||
time_t psl_inline_builtin_compile_time(void)
|
||||
{
|
||||
return _psl_compile_time;
|
||||
}
|
||||
|
||||
// returns mtime of PSL source file
|
||||
time_t psl_inline_builtin_file_time(void)
|
||||
{
|
||||
return _psl_file_time;
|
||||
}
|
||||
|
||||
// returns MD5 checksum of PSL source file
|
||||
const char *psl_inline_builtin_md5sum(void)
|
||||
{
|
||||
return _psl_md5_checksum;
|
||||
}
|
||||
|
|
63
src/psl2c.c
63
src/psl2c.c
|
@ -28,27 +28,31 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
//#ifdef WITH_LIBIDN2
|
||||
# include <idn2.h>
|
||||
//#endif
|
||||
|
||||
#include "psl.c"
|
||||
|
||||
static void _print_psl_entries(_psl_vector_t *v, const char *varname)
|
||||
static void _print_psl_entries(FILE *fpout, const _psl_vector_t *v, const char *varname)
|
||||
{
|
||||
int it;
|
||||
|
||||
printf("// automatically generated by psl2c\n");
|
||||
printf("static _psl_entry_t %s[] = {\n", varname);
|
||||
fprintf(fpout, "// automatically generated by psl2c\n");
|
||||
fprintf(fpout, "static _psl_entry_t %s[] = {\n", varname);
|
||||
|
||||
for (it = 0; it < v->cur; it++) {
|
||||
_psl_entry_t *e = _vector_get(v, it);
|
||||
|
||||
printf("\t{ \"%s\", NULL, %hd, %hhd, %hhd },\n",
|
||||
fprintf(fpout, "\t{ \"%s\", NULL, %hd, %hhd, %hhd },\n",
|
||||
e->label_buf, e->length, e->nlabels, e->wildcard);
|
||||
}
|
||||
|
||||
printf("};\n");
|
||||
fprintf(fpout, "};\n");
|
||||
}
|
||||
|
||||
static int _str_needs_encoding(const char *s)
|
||||
|
@ -83,20 +87,53 @@ static void _add_punycode_if_needed(_psl_vector_t *v)
|
|||
_vector_sort(v);
|
||||
}
|
||||
|
||||
// int main(int argc, const char **argv)
|
||||
int main(void)
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
FILE *fpout;
|
||||
psl_ctx_t *psl;
|
||||
int ret = 0;
|
||||
|
||||
if (!(psl = psl_load_fp(stdin)))
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: psl2c <infile> <outfile>\n");
|
||||
fprintf(stderr, " <infile> is the 'effective_tld_names.dat' (aka Public Suffix List)\n");
|
||||
fprintf(stderr, " <outfile> is the the C filename to be generated from <infile>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
_add_punycode_if_needed(psl->suffixes);
|
||||
_add_punycode_if_needed(psl->suffix_exceptions);
|
||||
if (!(psl = psl_load_file(argv[1])))
|
||||
return 2;
|
||||
|
||||
_print_psl_entries(psl->suffixes, "suffixes");
|
||||
_print_psl_entries(psl->suffix_exceptions, "suffix_exceptions");
|
||||
if ((fpout = fopen(argv[2], "w"))) {
|
||||
FILE *pp;
|
||||
struct stat st;
|
||||
char cmd[16 + strlen(argv[1])], checksum[64] = "";
|
||||
|
||||
_add_punycode_if_needed(psl->suffixes);
|
||||
_add_punycode_if_needed(psl->suffix_exceptions);
|
||||
|
||||
_print_psl_entries(fpout, psl->suffixes, "suffixes");
|
||||
_print_psl_entries(fpout, psl->suffix_exceptions, "suffix_exceptions");
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "md5sum %s", argv[1]);
|
||||
if ((pp = popen(cmd, "r"))) {
|
||||
if (fscanf(pp, "%63[0-9a-zA-Z]", checksum) < 1)
|
||||
*checksum = 0;
|
||||
pclose(pp);
|
||||
}
|
||||
|
||||
if (stat(argv[1], &st) != 0)
|
||||
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_md5_checksum[] = \"%s\";\n", checksum);
|
||||
|
||||
if (fclose(fpout) != 0)
|
||||
ret = 4;
|
||||
} else {
|
||||
fprintf(stderr, "Failed to write open '%s'\n", argv[2]);
|
||||
ret = 3;
|
||||
}
|
||||
|
||||
psl_free(&psl);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,15 @@ static void test_psl(void)
|
|||
}
|
||||
}
|
||||
|
||||
printf("psl_builtin_compile_time()=%ld\n", psl_inline_builtin_compile_time());
|
||||
psl_inline_builtin_compile_time() == 0 ? failed++ : ok++;
|
||||
|
||||
printf("psl_builtin_file_time()=%ld\n", psl_inline_builtin_file_time());
|
||||
psl_inline_builtin_file_time() == 0 ? failed++ : ok++;
|
||||
|
||||
printf("psl_builtin_md5sum()=%s\n", psl_inline_builtin_md5sum());
|
||||
*psl_inline_builtin_md5sum() == 0 ? failed++ : ok++;
|
||||
|
||||
psl_inline_deinit();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue