libtld 2.0.14
A library to determine the Top-Level Domain name of any Internet URI.
Classes | Macros | Enumerations | Functions
tld_file.h File Reference

Declaration of the TLD file structures. More...

#include <stdint.h>
#include <iostream>
Include dependency graph for tld_file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  auto_free_string
 
class  auto_free_tld_file
 
struct  tld_description
 [internal] The description of one TLD. More...
 
struct  tld_file
 
struct  tld_header
 
struct  tld_hunk
 
struct  tld_magic
 
struct  tld_string_length
 
struct  tld_string_offset
 
struct  tld_tag
 

Macros

#define TLD_DESCRIPTIONS   TLD_HUNK('D','E','S','C')
 
#define TLD_FILE_VERSION_MAJOR   1
 
#define TLD_FILE_VERSION_MINOR   0
 
#define TLD_HEADER   TLD_HUNK('H','E','A','D')
 
#define TLD_HUNK(a, b, c, d)   ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
 
#define TLD_MAGIC   TLD_HUNK('R','I','F','F')
 
#define TLD_STRING_LENGTHS   TLD_HUNK('S','L','E','N')
 
#define TLD_STRING_OFFSETS   TLD_HUNK('S','O','F','F')
 
#define TLD_STRINGS   TLD_HUNK('S','T','R','S')
 
#define TLD_TAGS   TLD_HUNK('T','A','G','S')
 
#define TLD_TLDS   TLD_HUNK('T','L','D','S')
 

Enumerations

enum  tld_file_error {
  TLD_FILE_ERROR_NONE = 0 , TLD_FILE_ERROR_INVALID_POINTER , TLD_FILE_ERROR_POINTER_PRESENT , TLD_FILE_ERROR_CANNOT_OPEN_FILE ,
  TLD_FILE_ERROR_CANNOT_READ_FILE , TLD_FILE_ERROR_UNRECOGNIZED_FILE , TLD_FILE_ERROR_INVALID_FILE_SIZE , TLD_FILE_ERROR_OUT_OF_MEMORY ,
  TLD_FILE_ERROR_INVALID_HUNK_SIZE , TLD_FILE_ERROR_INVALID_STRUCTURE_SIZE , TLD_FILE_ERROR_INVALID_ARRAY_SIZE , TLD_FILE_ERROR_UNSUPPORTED_VERSION ,
  TLD_FILE_ERROR_MISSING_HUNK , TLD_FILE_ERROR_HUNK_FOUND_TWICE
}
 

Functions

const struct tld_descriptiontld_file_description (struct tld_file const *file, uint32_t id)
 
const char * tld_file_errstr (enum tld_file_error err)
 
void tld_file_free (struct tld_file **file)
 
enum tld_file_error tld_file_load (const char *filename, struct tld_file **file)
 
enum tld_file_error tld_file_load_stream (tld_file **file, std::istream &in)
 
const char * tld_file_string (struct tld_file const *file, uint32_t id, uint32_t *length)
 
const struct tld_tagtld_file_tag (struct tld_file const *file, uint32_t id)
 
char * tld_file_to_json (struct tld_file const *file)
 

Detailed Description

The older version of the libtld had a pre-compiled structure within the library. The main problem with that designed is that you can't quickly update the list of domain name TLDs. You have to recompile the whole library, generate a new package, install that new package.

The pros are of course that you only have to deal with one file (.so or .a or similar file for your OS).

Yet, the number of TLDs has been growing and changing a lot back and forth in the last 10 years or so and having a compressed external file will make it a lot faster and a lot easier to update the available TLDs.

The structures found here describe that external file. The basic format is IFF (like a WAVE file, sizes and other numbers will be in the endian of your computer, so watch out on that part).

At time of writing, I have these hunks:

Definition in file tld_file.h.

Macro Definition Documentation

◆ TLD_DESCRIPTIONS

#define TLD_DESCRIPTIONS   TLD_HUNK('D','E','S','C')

Definition at line 75 of file tld_file.h.

◆ TLD_FILE_VERSION_MAJOR

#define TLD_FILE_VERSION_MAJOR   1

Definition at line 67 of file tld_file.h.

◆ TLD_FILE_VERSION_MINOR

#define TLD_FILE_VERSION_MINOR   0

Definition at line 68 of file tld_file.h.

◆ TLD_HEADER

#define TLD_HEADER   TLD_HUNK('H','E','A','D')

Definition at line 74 of file tld_file.h.

◆ TLD_HUNK

#define TLD_HUNK (   a,
  b,
  c,
 
)    ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))

Definition at line 70 of file tld_file.h.

◆ TLD_MAGIC

#define TLD_MAGIC   TLD_HUNK('R','I','F','F')

Definition at line 72 of file tld_file.h.

◆ TLD_STRING_LENGTHS

#define TLD_STRING_LENGTHS   TLD_HUNK('S','L','E','N')

Definition at line 78 of file tld_file.h.

◆ TLD_STRING_OFFSETS

#define TLD_STRING_OFFSETS   TLD_HUNK('S','O','F','F')

Definition at line 77 of file tld_file.h.

◆ TLD_STRINGS

#define TLD_STRINGS   TLD_HUNK('S','T','R','S')

Definition at line 79 of file tld_file.h.

◆ TLD_TAGS

#define TLD_TAGS   TLD_HUNK('T','A','G','S')

Definition at line 76 of file tld_file.h.

◆ TLD_TLDS

#define TLD_TLDS   TLD_HUNK('T','L','D','S')

Definition at line 73 of file tld_file.h.

Enumeration Type Documentation

◆ tld_file_error

enum tld_file_error

Definition at line 166 of file tld_file.h.

Function Documentation

◆ tld_file_errstr()

const char * tld_file_errstr ( enum tld_file_error  err)

Definition at line 298 of file tld_file.cpp.

◆ tld_file_free()

void tld_file_free ( struct tld_file **  file)

Definition at line 490 of file tld_file.cpp.

◆ tld_file_load()

enum tld_file_error tld_file_load ( const char *  filename,
struct tld_file **  file 
)

Definition at line 275 of file tld_file.cpp.

◆ tld_file_load_stream()

enum tld_file_error tld_file_load_stream ( tld_file **  file,
std::istream &  in 
)

Definition at line 51 of file tld_file.cpp.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.