libtld 2.0.14
A library to determine the Top-Level Domain name of any Internet URI.
tld_strings.c
Go to the documentation of this file.
1/* TLD library -- TLD, domain name, and sub-domain extraction
2 * Copyright (c) 2011-2025 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
30// self
31//
32#include "libtld/tld.h"
33
34
35// C
36//
37#include <string.h>
38
39
49const char * tld_status_to_string(enum tld_status status)
50{
51 switch(status)
52 {
54 return "valid";
55
57 return "proposed";
58
60 return "deprecated";
61
63 return "unused";
64
66 return "reserved";
67
69 return "infrastructure";
70
71 case TLD_STATUS_EXAMPLE:
72 return "example";
73
75 return "undefined";
76
78 return "exception";
79
80 }
81
82 return "unknown";
83}
84
85
103enum tld_category tld_word_to_category(const char *word, int n)
104{
105 char buf[32];
106
107 if(word != NULL
108 && (size_t) n < sizeof(buf))
109 {
110 // force all lowercase
111 //
112 for(int idx = 0; idx < n; ++idx)
113 {
114 if(word[idx] >= 'A' && word[idx] <= 'Z')
115 {
116 buf[idx] = word[idx] | 0x20;
117 }
118 else
119 {
120 buf[idx] = word[idx];
121 }
122 }
123 buf[n] = '\0';
124
125 switch(buf[0])
126 {
127 case 'b':
128 if(strcmp(buf, "brand") == 0)
129 {
130 return TLD_CATEGORY_BRAND;
131 }
132 break;
133
134 case 'c':
135 if(strcmp(buf, "contact") == 0)
136 {
138 }
139 if(strcmp(buf, "country") == 0)
140 {
142 }
143 break;
144
145 case 'e':
146 if(strcmp(buf, "entrepreneurial") == 0)
147 {
149 }
150 break;
151
152 case 'i':
153 if(strcmp(buf, "international") == 0)
154 {
156 }
157 break;
158
159 case 'g':
160 if(strcmp(buf, "group") == 0)
161 {
162 return TLD_CATEGORY_GROUP;
163 }
164 break;
165
166 case 'l':
167 if(strcmp(buf, "language") == 0)
168 {
170 }
171 if(strcmp(buf, "location") == 0)
172 {
174 }
175 break;
176
177 case 'p':
178 if(strcmp(buf, "professionals") == 0)
179 {
181 }
182 break;
183
184 case 'r':
185 if(strcmp(buf, "region") == 0)
186 {
187 return TLD_CATEGORY_REGION;
188 }
189 break;
190
191 case 't':
192 if(strcmp(buf, "technical") == 0)
193 {
195 }
196 break;
197
198 }
199 }
200
202}
203
204
205/* vim: ts=4 sw=4 et
206 */
The public header of the libtld library.
tld_category
Definition tld.h:54
@ TLD_CATEGORY_PROFESSIONALS
Professional TLDs.
Definition tld.h:56
@ TLD_CATEGORY_LANGUAGE
Language specific TLDs.
Definition tld.h:57
@ TLD_CATEGORY_BRAND
The TLD is owned and represents a brand.
Definition tld.h:64
@ TLD_CATEGORY_COUNTRY
A country extension.
Definition tld.h:61
@ TLD_CATEGORY_GROUP
Groups specific TLDs.
Definition tld.h:58
@ TLD_CATEGORY_TECHNICAL
Technical extensions are considered internal.
Definition tld.h:60
@ TLD_CATEGORY_LOCATION
Another region specific TLDs.
Definition tld.h:62
@ TLD_CATEGORY_INTERNATIONAL
International TLDs.
Definition tld.h:55
@ TLD_CATEGORY_UNDEFINED
The TLD was not found.
Definition tld.h:66
@ TLD_CATEGORY_ENTREPRENEURIAL
A private extension.
Definition tld.h:63
@ TLD_CATEGORY_REGION
Region specific TLDs.
Definition tld.h:59
@ TLD_CATEGORY_CONTACT
The attached TLD has contact information.
Definition tld.h:65
tld_status
Definition tld.h:70
@ TLD_STATUS_EXCEPTION
Special status to indicate an exception which is not directly a TLD.
Definition tld.h:88
@ TLD_STATUS_UNDEFINED
Special status to indicate we did not find the TLD.
Definition tld.h:78
@ TLD_STATUS_RESERVED
The TLD is reserved so no one can use it.
Definition tld.h:75
@ TLD_STATUS_VALID
The TLD is currently valid.
Definition tld.h:71
@ TLD_STATUS_INFRASTRUCTURE
These TLDs are reserved for the Internet infrastructure.
Definition tld.h:76
@ TLD_STATUS_UNUSED
The TLD was officially assigned but not put to use.
Definition tld.h:74
@ TLD_STATUS_DEPRECATED
The TLD was once in use.
Definition tld.h:73
@ TLD_STATUS_PROPOSED
The TLD was proposed but not yet accepted.
Definition tld.h:72
enum tld_category tld_word_to_category(const char *word, int n)
This is for backward compatibility.
const char * tld_status_to_string(enum tld_status status)
Transform the status to a string.
Definition tld_strings.c:49

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.