Add function psl_suffix_wildcard_count()
This commit is contained in:
parent
e443d21b61
commit
34289fa59b
|
@ -95,6 +95,9 @@ int
|
||||||
/* just counts exceptions */
|
/* just counts exceptions */
|
||||||
int
|
int
|
||||||
psl_suffix_exception_count(const psl_ctx_t *psl);
|
psl_suffix_exception_count(const psl_ctx_t *psl);
|
||||||
|
/* just counts wildcards */
|
||||||
|
int
|
||||||
|
psl_suffix_wildcard_count(const psl_ctx_t *psl);
|
||||||
/* returns compilation time */
|
/* returns compilation time */
|
||||||
time_t
|
time_t
|
||||||
psl_builtin_compile_time(void);
|
psl_builtin_compile_time(void);
|
||||||
|
|
25
src/psl.c
25
src/psl.c
|
@ -155,7 +155,8 @@ struct _psl_ctx_st {
|
||||||
*suffixes;
|
*suffixes;
|
||||||
int
|
int
|
||||||
nsuffixes,
|
nsuffixes,
|
||||||
nexceptions;
|
nexceptions,
|
||||||
|
nwildcards;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* include the PSL data compiled by 'psl2c' */
|
/* include the PSL data compiled by 'psl2c' */
|
||||||
|
@ -168,6 +169,7 @@ struct _psl_ctx_st {
|
||||||
static time_t _psl_compile_time;
|
static time_t _psl_compile_time;
|
||||||
static int _psl_nsuffixes;
|
static int _psl_nsuffixes;
|
||||||
static int _psl_nexceptions;
|
static int _psl_nexceptions;
|
||||||
|
static int _psl_nwildcards;
|
||||||
static const char _psl_sha1_checksum[] = "";
|
static const char _psl_sha1_checksum[] = "";
|
||||||
static const char _psl_filename[] = "";
|
static const char _psl_filename[] = "";
|
||||||
#endif
|
#endif
|
||||||
|
@ -730,6 +732,7 @@ psl_ctx_t *psl_load_fp(FILE *fp)
|
||||||
p++;
|
p++;
|
||||||
/* wildcard *.foo.bar implicitely make foo.bar a public suffix */
|
/* wildcard *.foo.bar implicitely make foo.bar a public suffix */
|
||||||
suffix.flags = _PSL_FLAG_WILDCARD | _PSL_FLAG_PLAIN;
|
suffix.flags = _PSL_FLAG_WILDCARD | _PSL_FLAG_PLAIN;
|
||||||
|
psl->nwildcards++;
|
||||||
psl->nsuffixes++;
|
psl->nsuffixes++;
|
||||||
} else {
|
} else {
|
||||||
if (!strchr(p, '.'))
|
if (!strchr(p, '.'))
|
||||||
|
@ -863,6 +866,26 @@ int psl_suffix_exception_count(const psl_ctx_t *psl)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* psl_suffix_wildcard_count:
|
||||||
|
* @psl: PSL context pointer
|
||||||
|
*
|
||||||
|
* This function returns number of public suffix wildcards maintained by @psl.
|
||||||
|
*
|
||||||
|
* Returns: Number of public suffix wildcards in PSL context.
|
||||||
|
*
|
||||||
|
* Since: 0.10.0
|
||||||
|
*/
|
||||||
|
int psl_suffix_wildcard_count(const psl_ctx_t *psl)
|
||||||
|
{
|
||||||
|
if (psl == &_builtin_psl)
|
||||||
|
return _psl_nwildcards;
|
||||||
|
else if (psl)
|
||||||
|
return psl->nwildcards;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* psl_builtin_compile_time:
|
* psl_builtin_compile_time:
|
||||||
*
|
*
|
||||||
|
|
|
@ -262,6 +262,7 @@ int main(int argc, const char **argv)
|
||||||
fprintf(fpout, "static time_t _psl_compile_time = %lu;\n", time(NULL));
|
fprintf(fpout, "static time_t _psl_compile_time = %lu;\n", time(NULL));
|
||||||
fprintf(fpout, "static int _psl_nsuffixes = %d;\n", psl->nsuffixes);
|
fprintf(fpout, "static int _psl_nsuffixes = %d;\n", psl->nsuffixes);
|
||||||
fprintf(fpout, "static int _psl_nexceptions = %d;\n", psl->nexceptions);
|
fprintf(fpout, "static int _psl_nexceptions = %d;\n", psl->nexceptions);
|
||||||
|
fprintf(fpout, "static int _psl_nwildcards = %d;\n", psl->nwildcards);
|
||||||
fprintf(fpout, "static const 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", argv[1]);
|
fprintf(fpout, "static const char _psl_filename[] = \"%s\";\n", argv[1]);
|
||||||
|
|
||||||
|
@ -280,6 +281,7 @@ int main(int argc, const char **argv)
|
||||||
fprintf(fpout, "static time_t _psl_compile_time;\n");
|
fprintf(fpout, "static time_t _psl_compile_time;\n");
|
||||||
fprintf(fpout, "static int _psl_nsuffixes = 0;\n");
|
fprintf(fpout, "static int _psl_nsuffixes = 0;\n");
|
||||||
fprintf(fpout, "static int _psl_nexceptions = 0;\n");
|
fprintf(fpout, "static int _psl_nexceptions = 0;\n");
|
||||||
|
fprintf(fpout, "static int _psl_nwildcards = 0;\n");
|
||||||
fprintf(fpout, "static const char _psl_sha1_checksum[] = \"\";\n");
|
fprintf(fpout, "static const char _psl_sha1_checksum[] = \"\";\n");
|
||||||
fprintf(fpout, "static const char _psl_filename[] = \"\";\n");
|
fprintf(fpout, "static const char _psl_filename[] = \"\";\n");
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,7 @@ int main(int argc, const char *const *argv)
|
||||||
if (psl && psl != psl_builtin()) {
|
if (psl && psl != psl_builtin()) {
|
||||||
printf("suffixes: %d\n", psl_suffix_count(psl));
|
printf("suffixes: %d\n", psl_suffix_count(psl));
|
||||||
printf("exceptions: %d\n", psl_suffix_exception_count(psl));
|
printf("exceptions: %d\n", psl_suffix_exception_count(psl));
|
||||||
|
printf("wildcards: %d\n", psl_suffix_wildcard_count(psl));
|
||||||
}
|
}
|
||||||
|
|
||||||
psl_free(psl);
|
psl_free(psl);
|
||||||
|
@ -208,6 +209,7 @@ int main(int argc, const char *const *argv)
|
||||||
if (psl) {
|
if (psl) {
|
||||||
printf("builtin suffixes: %d\n", psl_suffix_count(psl));
|
printf("builtin suffixes: %d\n", psl_suffix_count(psl));
|
||||||
printf("builtin exceptions: %d\n", psl_suffix_exception_count(psl));
|
printf("builtin exceptions: %d\n", psl_suffix_exception_count(psl));
|
||||||
|
printf("builtin wildcards: %d\n", psl_suffix_wildcard_count(psl));
|
||||||
printf("builtin filename: %s\n", psl_builtin_filename());
|
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 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 file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time()));
|
||||||
|
|
Loading…
Reference in New Issue