2014-03-20 22:43:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright(c) 2014 Tim Ruehsen
|
|
|
|
*
|
2014-03-24 17:29:56 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2014-03-20 22:43:04 +01:00
|
|
|
*
|
2014-03-24 17:29:56 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2014-03-20 22:43:04 +01:00
|
|
|
*
|
2014-03-24 17:29:56 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2014-03-20 22:43:04 +01:00
|
|
|
*
|
2014-03-24 17:29:56 +01:00
|
|
|
* This file is part of libpsl.
|
2014-03-20 22:43:04 +01:00
|
|
|
*
|
|
|
|
* Header file for libpsl library routines
|
|
|
|
*
|
|
|
|
* Changelog
|
|
|
|
* 20.03.2014 Tim Ruehsen created
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBPSL_LIBPSL_H
|
|
|
|
#define _LIBPSL_LIBPSL_H
|
|
|
|
|
2014-03-22 14:28:55 +01:00
|
|
|
#include <stdio.h>
|
2014-03-30 12:10:45 +02:00
|
|
|
#include <time.h>
|
2014-03-22 14:28:55 +01:00
|
|
|
|
2014-03-20 22:43:04 +01:00
|
|
|
#ifdef __cplusplus
|
2014-04-02 10:26:40 +02:00
|
|
|
extern "C" {
|
2014-03-20 22:43:04 +01:00
|
|
|
#endif
|
|
|
|
|
2014-06-20 17:12:17 +02:00
|
|
|
/**
|
|
|
|
* psl_error_t:
|
|
|
|
* @PSL_SUCCESS: Successful return.
|
|
|
|
* @PSL_ERR_INVALID_ARG: Invalid argument.
|
|
|
|
* @PSL_ERR_CONVERTER: Failed to open libicu utf-16 converter
|
|
|
|
* @PSL_ERR_TO_UTF16: Failed to convert to utf-16.
|
|
|
|
* @PSL_ERR_TO_LOWER: Failed to convert utf-16 to lowercase.
|
|
|
|
* @PSL_ERR_TO_UTF8: Failed to convert utf-16 to utf-8.
|
|
|
|
*
|
|
|
|
* Return codes for PSL functions.
|
|
|
|
* Negative return codes mean failure.
|
|
|
|
* Positive values are reserved for non-error return codes.
|
|
|
|
*/
|
2014-06-20 12:36:51 +02:00
|
|
|
typedef enum {
|
|
|
|
PSL_SUCCESS = 0,
|
|
|
|
PSL_ERR_INVALID_ARG = -1,
|
|
|
|
PSL_ERR_CONVERTER = -2, /* failed to open libicu utf-16 converter */
|
|
|
|
PSL_ERR_TO_UTF16 = -3, /* failed to convert to utf-16 */
|
|
|
|
PSL_ERR_TO_LOWER = -4, /* failed to convert utf-16 to lowercase */
|
|
|
|
PSL_ERR_TO_UTF8 = -5 /* failed to convert utf-16 to utf-8 */
|
|
|
|
} psl_error_t;
|
2014-03-20 22:43:04 +01:00
|
|
|
|
|
|
|
typedef struct _psl_ctx_st psl_ctx_t;
|
|
|
|
|
2014-05-12 12:20:59 +02:00
|
|
|
/* frees PSL context */
|
2014-03-20 22:43:04 +01:00
|
|
|
void
|
2014-03-27 18:16:54 +01:00
|
|
|
psl_free(psl_ctx_t *psl);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* loads PSL data from file */
|
2014-03-20 22:43:04 +01:00
|
|
|
psl_ctx_t *
|
|
|
|
psl_load_file(const char *fname);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* loads PSL data from FILE pointer */
|
2014-03-22 14:28:55 +01:00
|
|
|
psl_ctx_t *
|
|
|
|
psl_load_fp(FILE *fp);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* retrieves builtin PSL data */
|
2014-03-24 23:18:45 +01:00
|
|
|
const psl_ctx_t *
|
2014-03-24 17:29:56 +01:00
|
|
|
psl_builtin(void);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* checks wether domain is a public suffix or not */
|
2014-03-20 22:43:04 +01:00
|
|
|
int
|
2014-04-12 16:04:42 +02:00
|
|
|
psl_is_public_suffix(const psl_ctx_t *psl, const char *domain);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* checks wether cookie_domain is acceptable for domain or not */
|
2014-04-16 10:52:35 +02:00
|
|
|
int
|
|
|
|
psl_is_cookie_domain_acceptable(const psl_ctx_t *psl, const char *hostname, const char *cookie_domain);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* returns the longest unregistrable domain within 'domain' or NULL if none found */
|
2014-03-26 17:14:25 +01:00
|
|
|
const char *
|
2014-03-26 22:27:31 +01:00
|
|
|
psl_unregistrable_domain(const psl_ctx_t *psl, const char *domain);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* returns the shortest possible registrable domain part or NULL if domain is not registrable at all */
|
2014-03-26 22:27:31 +01:00
|
|
|
const char *
|
|
|
|
psl_registrable_domain(const psl_ctx_t *psl, const char *domain);
|
2014-06-17 17:14:02 +02:00
|
|
|
/* convert a string into lowercase UTF-8 */
|
2014-06-23 12:50:02 +02:00
|
|
|
psl_error_t
|
2014-06-18 14:50:26 +02:00
|
|
|
psl_str_to_utf8lower(const char *str, const char *encoding, const char *locale, char **lower);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* does not include exceptions */
|
2014-03-21 19:26:55 +01:00
|
|
|
int
|
|
|
|
psl_suffix_count(const psl_ctx_t *psl);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* just counts exceptions */
|
2014-03-21 19:26:55 +01:00
|
|
|
int
|
|
|
|
psl_suffix_exception_count(const psl_ctx_t *psl);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* returns compilation time */
|
2014-03-24 17:29:56 +01:00
|
|
|
time_t
|
|
|
|
psl_builtin_compile_time(void);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* returns mtime of PSL source file */
|
2014-03-24 17:29:56 +01:00
|
|
|
time_t
|
|
|
|
psl_builtin_file_time(void);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* returns SHA1 checksum (hex-encoded, lowercase) of PSL source file */
|
2014-03-24 17:29:56 +01:00
|
|
|
const char *
|
|
|
|
psl_builtin_sha1sum(void);
|
2014-05-12 12:20:59 +02:00
|
|
|
/* returns file name of PSL source file */
|
2014-04-17 12:31:06 +02:00
|
|
|
const char *
|
|
|
|
psl_builtin_filename(void);
|
2014-05-31 19:33:30 +02:00
|
|
|
/* returns library version */
|
|
|
|
const char *
|
|
|
|
psl_get_version(void);
|
2014-03-21 19:26:55 +01:00
|
|
|
|
|
|
|
|
2014-04-02 10:26:40 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-20 22:43:04 +01:00
|
|
|
|
|
|
|
#endif /* _LIBPSL_LIBPSL_H */
|