libtld: /home/snapwebsites/BUILD/contrib/libtld/include/libtld/tld.h Source File

libtld  1.5.13
A library to determine the Top-Level Domain name of any URL.
tld.h
Go to the documentation of this file.
1 /* TLD library -- TLD, domain name, and sub-domain extraction
2  * Copyright (c) 2011-2019 Made to Order Software Corp. All Rights Reserved
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef LIB_TLD_H
24 #define LIB_TLD_H
25 
32 #if ( defined(LIBTLD_DLL) || defined(_WINDLL) ) && ( defined(_WINDOWS) || defined(WINDOWS) )
33 #ifdef tld_EXPORTS
34 #define LIBTLD_EXPORT __declspec(dllexport)
35 #else
36 #define LIBTLD_EXPORT __declspec(dllimport)
37 #endif
38 #else
39 #define LIBTLD_EXPORT
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #define LIBTLD_VERSION_MAJOR 1
47 #define LIBTLD_VERSION_MINOR 5
48 #define LIBTLD_VERSION_PATCH 13
49 #define LIBTLD_VERSION "1.5.13"
50 
52 {
63 };
64 
66 {
74 
75  /* The following status is never returned. It is used internally to handle
76  * exceptions (i.e. usually 2nd level domain names that should not be.)
77  */
79 };
80 
82 {
84  TLD_RESULT_INVALID, /* TLD not acceptable (reserved, deprecated, etc.) */
85  TLD_RESULT_NULL, /* URI is a NULL pointer */
86  TLD_RESULT_NO_TLD, /* no '.' in the URI */
87  TLD_RESULT_BAD_URI, /* URI includes two '.' one after another or some other problem */
89 };
90 
91 struct tld_info
92 {
95  const char * f_country;
96  const char * f_tld; /* pointer within your URI string */
97  int f_offset;
98 };
99 
100 #define VALID_URI_ASCII_ONLY 0x0001
101 #define VALID_URI_NO_SPACES 0x0002
102 
103 
104 extern LIBTLD_EXPORT const char *tld_version();
105 
106 
107 extern LIBTLD_EXPORT void tld_clear_info(struct tld_info *info);
108 extern LIBTLD_EXPORT enum tld_result tld(const char *uri, struct tld_info *info);
109 extern LIBTLD_EXPORT enum tld_result tld_check_uri(const char *uri, struct tld_info *info, const char *protocols, int flags);
110 extern LIBTLD_EXPORT char *tld_domain_to_lowercase(const char *domain);
111 
112 
113 
114 struct tld_email
115 {
116  const char * f_group;
117  const char * f_original_email;
118  const char * f_fullname;
119  const char * f_username;
120  const char * f_domain;
121  const char * f_email_only;
122  const char * f_canonicalized_email;
123 };
124 
126 {
133 };
134 
135 struct tld_email_list;
136 
138 extern LIBTLD_EXPORT void tld_email_free(struct tld_email_list *list);
139 extern LIBTLD_EXPORT enum tld_result tld_email_parse(struct tld_email_list *list, const char *emails, int flags);
142 extern LIBTLD_EXPORT int tld_email_next(struct tld_email_list *list, struct tld_email *e);
143 
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #ifdef __cplusplus
150 /* For C++ users */
151 #include <string>
152 #include <vector>
153 #include <stdexcept>
154 struct invalid_domain : public std::runtime_error
155 {
156  invalid_domain(const char *what_str = "this tld object is not currently valid") : runtime_error(what_str) {}
157 };
159 {
160 public:
161  tld_object(const char *domain_name = NULL);
162  tld_object(const std::string& domain_name);
163  void set_domain(const char *domain_name);
164  void set_domain(const std::string& domain_name);
165  tld_result result() const;
166  tld_status status() const;
167  bool is_valid() const;
168  std::string domain() const;
169  std::string sub_domains() const;
170  std::string full_domain() const;
171  std::string domain_only() const;
172  std::string tld_only() const;
173  tld_category category() const;
174  std::string country() const;
175 private:
176  std::string f_domain = std::string();
177  tld_info f_info = tld_info();
179 };
180 
182 {
183 public:
184  struct tld_email_t
185  {
186  tld_result parse(const std::string& email);
187  tld_result parse_group(const std::string& group);
188 
189  std::string f_group = std::string();
190  std::string f_original_email = std::string();
191  std::string f_fullname = std::string();
192  std::string f_username = std::string();
193  std::string f_domain = std::string();
194  std::string f_email_only = std::string();
195  std::string f_canonicalized_email = std::string();
196  };
197  typedef std::vector<tld_email_t> tld_email_list_t;
198 
199  tld_email_list();
200  tld_result parse(const std::string& emails, int flags);
201  static std::string quote_string(const std::string& name, char quote);
202  int count() const;
203  void rewind() const;
204  bool next(tld_email_t& e) const;
205  bool next(tld_email *e) const;
206 
207  static tld_email_field_type email_field_type(const std::string& name);
208 
209 private:
210  void parse_all_emails();
211 
212  std::string f_input = std::string();
213  int f_flags = 0;
215  std::string f_last_group = std::string();
216  mutable int f_pos = 0;
217  tld_email_list_t f_email_list = tld_email_list_t();
218 };
219 #endif
220 
221 #endif
222 /*#ifndef LIB_TLD_H*/
223 /* vim: ts=4 sw=4 et
224  */
tld_status
Defines the current status of the TLD.
Definition: tld.h:65
The input represents an optional list of email addresses.
Definition: tld.h:132
Special status to indicate an exception which is not directly a TLD.
Definition: tld.h:78
Language specific TLDs.
Definition: tld.h:55
enum tld_status f_status
The status of the TLD.
Definition: tld.h:94
A private extension.
Definition: tld.h:60
LIBTLD_EXPORT void tld_clear_info(struct tld_info *info)
Clear the info structure.
Definition: tld.c:441
const char * f_tld
Pointer to the TLD in the URI string you supplied.
Definition: tld.h:96
LIBTLD_EXPORT enum tld_result tld(const char *uri, struct tld_info *info)
Get information about the TLD for the specified URI.
Definition: tld.c:555
invalid_domain(const char *what_str="this tld object is not currently valid")
Initialize the invalid_domain exception.
Definition: tld.h:156
const char * f_email_only
The complete email address without display name.
Definition: tld.h:121
LIBTLD_EXPORT char * tld_domain_to_lowercase(const char *domain)
Transform a domain with a TLD to lowercase before processing.
The input URI is empty.
Definition: tld.h:85
#define LIBTLD_EXPORT
The export API used by MS-Windows DLLs.
const char * f_fullname
The user full or display name.
Definition: tld.h:118
The C++ side of the email list implementation.
Definition: tld.h:181
Class used to ease the use o the tld() function in C++.
Definition: tld.h:158
LIBTLD_EXPORT int tld_email_count(struct tld_email_list *list)
Return the number of emails found after a parse.
LIBTLD_EXPORT struct tld_email_list * tld_email_alloc()
Allocate a list of emails object.
std::vector< tld_email_t > tld_email_list_t
A vector of email details.
Definition: tld.h:197
int f_offset
The offset to the TLD in the URI string you supplied.
Definition: tld.h:97
const char * f_original_email
The email as read from the source.
Definition: tld.h:117
tld_category
The list of categories for the different TLDs.
Definition: tld.h:51
const char * f_canonicalized_email
The email including the display name.
Definition: tld.h:122
The input represents a mailbox list.
Definition: tld.h:129
const char * f_username
The user being named in this email address.
Definition: tld.h:119
Parts of one email.
Definition: tld.h:184
The TLD was found, but it is marked as invalid.
Definition: tld.h:84
The TLD is reserved so no one can use it.
Definition: tld.h:71
Special status to indicate we did not find the TLD.
Definition: tld.h:73
LIBTLD_EXPORT void tld_email_free(struct tld_email_list *list)
Free the list of emails.
The TLD was once in use.
Definition: tld.h:69
LIBTLD_EXPORT int tld_email_next(struct tld_email_list *list, struct tld_email *e)
Retrieve the next email.
LIBTLD_EXPORT enum tld_result tld_check_uri(const char *uri, struct tld_info *info, const char *protocols, int flags)
Check that a URI is valid.
Definition: tld.c:741
The input does not represent valid emails.
Definition: tld.h:128
void list()
List the default schemes accepted.
The URI has a TLD that could not be determined.
Definition: tld.h:88
A country extension.
Definition: tld.h:59
The input represents a mailbox.
Definition: tld.h:130
The input of email_field_type() was not valid.
Definition: tld.h:127
const char * f_group
The group this emails was defined in.
Definition: tld.h:116
The input URI has no TLD defined.
Definition: tld.h:86
The TLD was not found.
Definition: tld.h:62
Professional TLDs.
Definition: tld.h:54
The TLD is owned and represents a brand.
Definition: tld.h:61
The TLD is currently valid.
Definition: tld.h:67
const char * f_domain
The domain part of the email address.
Definition: tld.h:120
The URI includes characters that are not accepted by the function.
Definition: tld.h:87
Exception thrown when querying for data of an invalid domain.
Definition: tld.h:154
Technical extensions are considered internal.
Definition: tld.h:58
International TLDs.
Definition: tld.h:53
LIBTLD_EXPORT const char * tld_version()
Return the version of the library.
Definition: tld.c:1043
tld_result
The result returned by tld().
Definition: tld.h:81
LIBTLD_EXPORT enum tld_result tld_email_parse(struct tld_email_list *list, const char *emails, int flags)
Parse a list of emails in the email list object.
Success! The TLD of the specified URI is valid.
Definition: tld.h:83
const char * f_country
The country where this TLD is used.
Definition: tld.h:95
Parts of one email.
Definition: tld.h:114
The TLD was proposed but not yet accepted.
Definition: tld.h:68
enum tld_category f_category
The category of the TLD.
Definition: tld.h:93
Set of information returned by the tld() function.
Definition: tld.h:91
Region specific TLDs.
Definition: tld.h:57
The input represents a mandatory list of mailboxes.
Definition: tld.h:131
The TLD was officially assigned but not put to use.
Definition: tld.h:70
These TLDs are reserved for the Internet infrastructure.
Definition: tld.h:72
tld_email_field_type
Type of email as determined by the email_field_type() function.
Definition: tld.h:125
LIBTLD_EXPORT void tld_email_rewind(struct tld_email_list *list)
Rewind the reading of the emails.
Groups specific TLDs.
Definition: tld.h:56

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly