2015-09-23 12:38:34 +02:00
|
|
|
/*
|
2018-02-22 10:03:37 +01:00
|
|
|
* Copyright(c) 2014-2018 Tim Ruehsen
|
2015-09-23 12:38:34 +02: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:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This file is part of libpsl.
|
|
|
|
*
|
|
|
|
* Header file for libpsl library routines
|
|
|
|
*
|
|
|
|
* Changelog
|
|
|
|
* 20.03.2014 Tim Ruehsen created
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-04-19 10:16:45 +02:00
|
|
|
#ifndef LIBPSL_LIBPSL_H
|
|
|
|
#define LIBPSL_LIBPSL_H
|
2015-09-23 12:38:34 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#define PSL_VERSION "@LIBPSL_VERSION@"
|
|
|
|
#define PSL_VERSION_MAJOR @LIBPSL_VERSION_MAJOR@
|
|
|
|
#define PSL_VERSION_MINOR @LIBPSL_VERSION_MINOR@
|
|
|
|
#define PSL_VERSION_PATCH @LIBPSL_VERSION_PATCH@
|
|
|
|
#define PSL_VERSION_NUMBER @LIBPSL_VERSION_NUMBER@
|
|
|
|
|
2018-09-25 02:17:48 +02:00
|
|
|
// support clang's __has_declspec_attribute attribute
|
|
|
|
#ifndef __has_declspec_attribute
|
|
|
|
# define __has_declspec_attribute(x) 0
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 10:06:47 +02:00
|
|
|
#ifndef PSL_API
|
|
|
|
#if defined BUILDING_PSL && HAVE_VISIBILITY
|
|
|
|
# define PSL_API __attribute__ ((__visibility__("default")))
|
2018-09-25 02:17:48 +02:00
|
|
|
#elif defined BUILDING_PSL && (defined _MSC_VER || __has_declspec_attribute(dllexport)) && !defined PSL_STATIC
|
2018-04-19 10:06:47 +02:00
|
|
|
# define PSL_API __declspec(dllexport)
|
2018-09-25 02:17:48 +02:00
|
|
|
#elif (defined _MSC_VER || __has_declspec_attribute(dllimport)) && !defined PSL_STATIC
|
2018-04-19 10:06:47 +02:00
|
|
|
# define PSL_API __declspec(dllimport)
|
|
|
|
#else
|
|
|
|
# define PSL_API
|
|
|
|
#endif
|
2018-04-18 07:52:38 +02:00
|
|
|
#endif
|
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-07-05 18:58:13 +02:00
|
|
|
/* types for psl_is_public_suffix2() */
|
2018-02-21 15:20:36 +01:00
|
|
|
#define PSL_TYPE_ICANN (1<<0)
|
|
|
|
#define PSL_TYPE_PRIVATE (1<<1)
|
|
|
|
#define PSL_TYPE_NO_STAR_RULE (1<<2)
|
|
|
|
#define PSL_TYPE_ANY (PSL_TYPE_ICANN | PSL_TYPE_PRIVATE)
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/**
|
|
|
|
* psl_error_t:
|
|
|
|
* @PSL_SUCCESS: Successful return.
|
|
|
|
* @PSL_ERR_INVALID_ARG: Invalid argument.
|
2016-09-21 11:13:02 +02:00
|
|
|
* @PSL_ERR_CONVERTER: Failed to open libicu utf-16 converter.
|
2015-09-23 12:38:34 +02:00
|
|
|
* @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.
|
2016-09-21 11:13:02 +02:00
|
|
|
* @PSL_ERR_NO_MEM: Failed to allocate memory.
|
2015-09-23 12:38:34 +02:00
|
|
|
*
|
|
|
|
* Return codes for PSL functions.
|
|
|
|
* Negative return codes mean failure.
|
|
|
|
* Positive values are reserved for non-error return codes.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
PSL_SUCCESS = 0,
|
|
|
|
PSL_ERR_INVALID_ARG = -1,
|
|
|
|
PSL_ERR_CONVERTER = -2, /* failed to open libicu utf-16 converter */
|
2016-09-21 11:13:02 +02:00
|
|
|
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_ERR_NO_MEM = -6 /* failed to allocate memory */
|
2015-09-23 12:38:34 +02:00
|
|
|
} psl_error_t;
|
|
|
|
|
2018-10-29 12:16:52 +01:00
|
|
|
typedef struct psl_ctx_st psl_ctx_t;
|
2015-09-23 12:38:34 +02:00
|
|
|
|
|
|
|
/* frees PSL context */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
void
|
|
|
|
psl_free(psl_ctx_t *psl);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2017-08-29 19:32:47 +02:00
|
|
|
/* frees memory allocated by libpsl routines */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2017-08-29 19:32:47 +02:00
|
|
|
void
|
|
|
|
psl_free_string(char *str);
|
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* loads PSL data from file */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
psl_ctx_t *
|
|
|
|
psl_load_file(const char *fname);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* loads PSL data from FILE pointer */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
psl_ctx_t *
|
|
|
|
psl_load_fp(FILE *fp);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* retrieves builtin PSL data */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
const psl_ctx_t *
|
|
|
|
psl_builtin(void);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2016-12-05 14:48:49 +01:00
|
|
|
/* retrieves most recent PSL data */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2016-12-05 14:48:49 +01:00
|
|
|
psl_ctx_t *
|
|
|
|
psl_latest(const char *fname);
|
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* checks whether domain is a public suffix or not */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
int
|
|
|
|
psl_is_public_suffix(const psl_ctx_t *psl, const char *domain);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
|
|
|
/* checks whether domain is a public suffix regarding the type or not */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-12-06 21:55:56 +01:00
|
|
|
int
|
|
|
|
psl_is_public_suffix2(const psl_ctx_t *psl, const char *domain, int type);
|
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* checks whether cookie_domain is acceptable for domain or not */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
int
|
|
|
|
psl_is_cookie_domain_acceptable(const psl_ctx_t *psl, const char *hostname, const char *cookie_domain);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* returns the longest not registrable domain within 'domain' or NULL if none found */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
const char *
|
|
|
|
psl_unregistrable_domain(const psl_ctx_t *psl, const char *domain);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* returns the shortest possible registrable domain part or NULL if domain is not registrable at all */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
const char *
|
|
|
|
psl_registrable_domain(const psl_ctx_t *psl, const char *domain);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* convert a string into lowercase UTF-8 */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
psl_error_t
|
|
|
|
psl_str_to_utf8lower(const char *str, const char *encoding, const char *locale, char **lower);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* does not include exceptions */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
int
|
|
|
|
psl_suffix_count(const psl_ctx_t *psl);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* just counts exceptions */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
int
|
|
|
|
psl_suffix_exception_count(const psl_ctx_t *psl);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* just counts wildcards */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
int
|
|
|
|
psl_suffix_wildcard_count(const psl_ctx_t *psl);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* returns mtime of PSL source file */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
time_t
|
|
|
|
psl_builtin_file_time(void);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* returns SHA1 checksum (hex-encoded, lowercase) of PSL source file */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
const char *
|
|
|
|
psl_builtin_sha1sum(void);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 12:38:34 +02:00
|
|
|
/* returns file name of PSL source file */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
const char *
|
|
|
|
psl_builtin_filename(void);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2016-12-05 14:48:49 +01:00
|
|
|
/* returns name of distribution PSL data file */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2016-12-05 14:48:49 +01:00
|
|
|
const char *
|
|
|
|
psl_dist_filename(void);
|
|
|
|
|
2015-09-23 14:04:17 +02:00
|
|
|
/* returns library version string */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
const char *
|
|
|
|
psl_get_version(void);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2015-09-23 14:04:17 +02:00
|
|
|
/* checks library version number */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 14:04:17 +02:00
|
|
|
int
|
|
|
|
psl_check_version_number(int version);
|
2015-12-06 21:55:56 +01:00
|
|
|
|
2017-04-19 11:46:27 +02:00
|
|
|
/* returns whether the built-in data is outdated or not */
|
2018-04-19 10:06:47 +02:00
|
|
|
PSL_API
|
2015-09-23 12:38:34 +02:00
|
|
|
int
|
|
|
|
psl_builtin_outdated(void);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 10:16:45 +02:00
|
|
|
#endif /* LIBPSL_LIBPSL_H */
|