|
libidn
1.25
|
00001 /* tld.h --- Declarations for TLD restriction checking. 00002 Copyright (C) 2004-2012 Simon Josefsson. 00003 Copyright (C) 2003-2012 Free Software Foundation, Inc. 00004 00005 Author: Thomas Jacob, Internet24.de 00006 00007 This file is part of GNU Libidn. 00008 00009 GNU Libidn is free software: you can redistribute it and/or 00010 modify it under the terms of either: 00011 00012 * the GNU Lesser General Public License as published by the Free 00013 Software Foundation; either version 3 of the License, or (at 00014 your option) any later version. 00015 00016 or 00017 00018 * the GNU General Public License as published by the Free 00019 Software Foundation; either version 2 of the License, or (at 00020 your option) any later version. 00021 00022 or both in parallel, as here. 00023 00024 GNU Libidn is distributed in the hope that it will be useful, 00025 but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00027 General Public License for more details. 00028 00029 You should have received copies of the GNU General Public License and 00030 the GNU Lesser General Public License along with this program. If 00031 not, see <http://www.gnu.org/licenses/>. */ 00032 00033 #ifndef TLD_H 00034 # define TLD_H 00035 00036 # ifndef IDNAPI 00037 # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY 00038 # define IDNAPI __attribute__((__visibility__("default"))) 00039 # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC 00040 # define IDNAPI __declspec(dllexport) 00041 # elif defined _MSC_VER && ! defined LIBIDN_STATIC 00042 # define IDNAPI __declspec(dllimport) 00043 # else 00044 # define IDNAPI 00045 # endif 00046 # endif 00047 00048 # ifdef __cplusplus 00049 extern "C" 00050 { 00051 # endif 00052 00053 /* Get size_t. */ 00054 # include <stdlib.h> 00055 00056 /* Get uint32_t. */ 00057 # include <idn-int.h> 00058 00059 /* Interval of valid code points in the TLD. */ 00060 struct Tld_table_element 00061 { 00062 uint32_t start; /* Start of range. */ 00063 uint32_t end; /* End of range, end == start if single. */ 00064 }; 00065 typedef struct Tld_table_element Tld_table_element; 00066 00067 /* List valid code points in a TLD. */ 00068 struct Tld_table 00069 { 00070 const char *name; /* TLD name, e.g., "no". */ 00071 const char *version; /* Version string from TLD file. */ 00072 size_t nvalid; /* Number of entries in data. */ 00073 const Tld_table_element *valid; /* Sorted array of valid code points. */ 00074 }; 00075 typedef struct Tld_table Tld_table; 00076 00077 /* Error codes. */ 00078 typedef enum 00079 { 00080 TLD_SUCCESS = 0, 00081 TLD_INVALID = 1, /* Invalid character found. */ 00082 TLD_NODATA = 2, /* Char, domain or inlen = 0. */ 00083 TLD_MALLOC_ERROR = 3, 00084 TLD_ICONV_ERROR = 4, 00085 TLD_NO_TLD = 5, 00086 /* Workaround typo in earlier versions. */ 00087 TLD_NOTLD = TLD_NO_TLD 00088 } Tld_rc; 00089 00090 extern IDNAPI const char *tld_strerror (Tld_rc rc); 00091 00092 /* Extract TLD, as ASCII string, of UCS4 domain name into "out". */ 00093 extern IDNAPI int tld_get_4 (const uint32_t * in, size_t inlen, 00094 char **out); 00095 extern IDNAPI int tld_get_4z (const uint32_t * in, char **out); 00096 extern IDNAPI int tld_get_z (const char *in, char **out); 00097 00098 /* Return structure corresponding to the named TLD from specified 00099 * list of TLD tables, or return NULL if no matching TLD can be 00100 * found. */ 00101 extern IDNAPI const Tld_table *tld_get_table (const char *tld, 00102 const Tld_table ** tables); 00103 00104 /* Return structure corresponding to the named TLD, first looking 00105 * thru overrides then thru built-in list, or return NULL if no 00106 * matching TLD can be found. */ 00107 extern IDNAPI const Tld_table * tld_default_table (const char *tld, 00108 const Tld_table ** overrides); 00109 00110 /* Check NAMEPREPPED domain name for valid characters as defined by 00111 * the relevant registering body (plus [a-z0-9.-]). If error is 00112 * TLD_INVALID, set errpos to position of offending character. */ 00113 extern IDNAPI int tld_check_4t (const uint32_t * in, size_t inlen, 00114 size_t * errpos, const Tld_table * tld); 00115 extern IDNAPI int tld_check_4tz (const uint32_t * in, size_t * errpos, 00116 const Tld_table * tld); 00117 00118 /* Utility interfaces that uses tld_get_4* to find TLD of string, 00119 then tld_default_table (with overrides) to find proper TLD table 00120 for the string, and then hands over to tld_check_4t*. */ 00121 extern IDNAPI int tld_check_4 (const uint32_t * in, size_t inlen, 00122 size_t * errpos, 00123 const Tld_table ** overrides); 00124 extern IDNAPI int tld_check_4z (const uint32_t * in, size_t * errpos, 00125 const Tld_table ** overrides); 00126 extern IDNAPI int tld_check_8z (const char *in, size_t * errpos, 00127 const Tld_table ** overrides); 00128 extern IDNAPI int tld_check_lz (const char *in, size_t * errpos, 00129 const Tld_table ** overrides); 00130 00131 # ifdef __cplusplus 00132 } 00133 # endif 00134 00135 #endif /* TLD_H */
1.7.6.1