tld.h

Go to the documentation of this file.
00001 /* tld.h --- Declarations for TLD restriction checking.
00002  * Copyright (C) 2004  Simon Josefsson.
00003  * Copyright (C) 2003, 2004  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 the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * GNU Libidn is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with GNU Libidn; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00022  *
00023  */
00024 
00025 #ifndef _TLD_H
00026 #define _TLD_H
00027 
00028 #ifdef __cplusplus
00029 extern "C"
00030 {
00031 #endif
00032 
00033   /* Get size_t. */
00034 #include <stdlib.h>
00035 
00036   /* Get uint32_t. */
00037 #include <idn-int.h>
00038 
00039   /* Interval of valid code points in the TLD. */
00040   struct Tld_table_element
00041   {
00042     uint32_t start;             /* Start of range. */
00043     uint32_t end;               /* End of range, end == start if single. */
00044   };
00045   typedef struct Tld_table_element Tld_table_element;
00046 
00047   /* List valid code points in a TLD. */
00048   struct Tld_table
00049   {
00050     const char *name;           /* TLD name, e.g., "no". */
00051     const char *version;        /* Version string from TLD file. */
00052     size_t nvalid;              /* Number of entries in data. */
00053     const Tld_table_element *valid;     /* Sorted array of valid code points. */
00054   };
00055   typedef struct Tld_table Tld_table;
00056 
00057   /* Error codes. */
00058   typedef enum
00059   {
00060     TLD_SUCCESS = 0,
00061     TLD_INVALID = 1,            /* Invalid character found. */
00062     TLD_NODATA = 2,             /* Char, domain or inlen = 0. */
00063     TLD_MALLOC_ERROR = 3,
00064     TLD_ICONV_ERROR = 4,
00065     TLD_NO_TLD = 5,
00066     /* Workaround typo in earlier versions. */
00067     TLD_NOTLD = TLD_NO_TLD
00068   } Tld_rc;
00069 
00070   extern const char *tld_strerror (Tld_rc rc);
00071 
00072   /* Extract TLD, as ASCII string, of UCS4 domain name into "out". */
00073   int tld_get_4 (const uint32_t * in, size_t inlen, char **out);
00074   int tld_get_4z (const uint32_t * in, char **out);
00075   int tld_get_z (const char *in, char **out);
00076 
00077   /* Return structure corresponding to the named TLD from specified
00078    * list of TLD tables, or return NULL if no matching TLD can be
00079    * found. */
00080   const Tld_table *tld_get_table (const char *tld, const Tld_table ** tables);
00081 
00082   /* Return structure corresponding to the named TLD, first looking
00083    * thru overrides then thru built-in list, or return NULL if no
00084    * matching TLD can be found. */
00085   const Tld_table *tld_default_table (const char *tld,
00086                                       const Tld_table ** overrides);
00087 
00088   /* Check NAMEPREPPED domain name for valid characters as defined by
00089    * the relevant registering body (plus [a-z0-9.-]).  If error is
00090    * TLD_INVALID, set errpos to position of offending character. */
00091   int tld_check_4t (const uint32_t * in, size_t inlen, size_t * errpos,
00092                     const Tld_table * tld);
00093   int tld_check_4tz (const uint32_t * in, size_t * errpos,
00094                      const Tld_table * tld);
00095 
00096   /* Utility interfaces that uses tld_get_4* to find TLD of string,
00097      then tld_default_table (with overrides) to find proper TLD table
00098      for the string, and then hands over to tld_check_4t*. */
00099   int tld_check_4 (const uint32_t * in, size_t inlen, size_t * errpos,
00100                    const Tld_table ** overrides);
00101   int tld_check_4z (const uint32_t * in, size_t * errpos,
00102                     const Tld_table ** overrides);
00103   int tld_check_8z (const char *in, size_t * errpos,
00104                     const Tld_table ** overrides);
00105   int tld_check_lz (const char *in, size_t * errpos,
00106                     const Tld_table ** overrides);
00107 
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111 #endif                          /* _TLD_H */

Generated on Wed Sep 13 10:20:31 2006 for libidn by  doxygen 1.4.7