LCOV - code coverage report
Current view: top level - tmp/coverage/BUILD/include/libtld - tld.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2018-01-27 17:32:31 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* TLD library -- TLD, domain name, and sub-domain extraction
       2             :  * Copyright (C) 2011-2017  Made to Order Software Corp.
       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             : /** \file
      26             :  * \brief The public header of the libtld library.
      27             :  *
      28             :  * This file declares all the functions, objects, structures, etc. publicly
      29             :  * available from the libtld library.
      30             :  */
      31             : 
      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    9
      49             : #define LIBTLD_VERSION          "1.5.9"
      50             : 
      51             : enum tld_category
      52             : {
      53             :     TLD_CATEGORY_INTERNATIONAL,
      54             :     TLD_CATEGORY_PROFESSIONALS,
      55             :     TLD_CATEGORY_LANGUAGE,
      56             :     TLD_CATEGORY_GROUPS,
      57             :     TLD_CATEGORY_REGION,
      58             :     TLD_CATEGORY_TECHNICAL,
      59             :     TLD_CATEGORY_COUNTRY,
      60             :     TLD_CATEGORY_ENTREPRENEURIAL,
      61             :     TLD_CATEGORY_BRAND,
      62             :     TLD_CATEGORY_UNDEFINED
      63             : };
      64             : 
      65             : enum tld_status
      66             : {
      67             :     TLD_STATUS_VALID,
      68             :     TLD_STATUS_PROPOSED,
      69             :     TLD_STATUS_DEPRECATED,
      70             :     TLD_STATUS_UNUSED,
      71             :     TLD_STATUS_RESERVED,
      72             :     TLD_STATUS_INFRASTRUCTURE,
      73             :     TLD_STATUS_UNDEFINED,
      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             :      */
      78             :     TLD_STATUS_EXCEPTION = 100
      79             : };
      80             : 
      81             : enum tld_result
      82             : {
      83             :     TLD_RESULT_SUCCESS,
      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 */
      88             :     TLD_RESULT_NOT_FOUND
      89             : };
      90             : 
      91             : struct tld_info
      92             : {
      93             :     enum tld_category   f_category;
      94             :     enum tld_status     f_status;
      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             : 
     125             : enum tld_email_field_type
     126             : {
     127             :     TLD_EMAIL_FIELD_TYPE_INVALID = -1,
     128             :     TLD_EMAIL_FIELD_TYPE_UNKNOWN,
     129             :     TLD_EMAIL_FIELD_TYPE_MAILBOX_LIST,
     130             :     TLD_EMAIL_FIELD_TYPE_MAILBOX,
     131             :     TLD_EMAIL_FIELD_TYPE_ADDRESS_LIST,
     132             :     TLD_EMAIL_FIELD_TYPE_ADDRESS_LIST_OPT
     133             : };
     134             : 
     135             : struct tld_email_list;
     136             : 
     137             : extern LIBTLD_EXPORT struct tld_email_list *tld_email_alloc();
     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);
     140             : extern LIBTLD_EXPORT int tld_email_count(struct tld_email_list *list);
     141             : extern LIBTLD_EXPORT void tld_email_rewind(struct tld_email_list *list);
     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          12 : struct invalid_domain : public std::runtime_error
     155             : {
     156          12 :     invalid_domain(const char *what_str = "this tld object is not currently valid") : runtime_error(what_str) {}
     157             : };
     158           7 : class LIBTLD_EXPORT tld_object
     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;
     177             :     tld_info f_info;
     178             :     tld_result f_result;
     179             : };
     180             : 
     181         626 : struct LIBTLD_EXPORT tld_email_list
     182             : {
     183             : public:
     184        2581 :     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;
     190             :         std::string         f_original_email;
     191             :         std::string         f_fullname;
     192             :         std::string         f_username;
     193             :         std::string         f_domain;
     194             :         std::string         f_email_only;
     195             :         std::string         f_canonicalized_email;
     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;
     213             :     int                 f_flags;
     214             :     tld_result          f_result;
     215             :     std::string         f_last_group;
     216             :     mutable int         f_pos;
     217             :     tld_email_list_t    f_email_list;
     218             : };
     219             : #endif
     220             : 
     221             : #endif
     222             : /*#ifndef LIB_TLD_H*/
     223             : /* vim: ts=4 sw=4 et
     224             :  */

Generated by: LCOV version 1.12