|
| rhostname () noexcept |
| Instantiate an empty rhostname that doesn't qualify as a properly-formatted hostname (because the minimum length of a valid hostname is 1 character).
|
|
| rhostname (const char *hostname, const size_t len=0, const int flags=rlabel::HOSTNAME_DEFAULT) |
| Instantiate an rhostname.
|
|
| rhostname (const std::string hostname, const int flags=rlabel::HOSTNAME_DEFAULT) |
| Instantiate an rhostname.
|
|
rhostname * | clear () |
| Clear this rhostname's underlying hostname and reset all states.
|
|
const bool | is_fqdn () noexcept |
| Find out whether this hostname is an FQDN (it has a final dot).
|
|
rhostname * | is_fqdn (const bool mode) noexcept |
| Specify whether this hostname is an FQDN (has a final dot).
|
|
const bool | is_utf8 () noexcept |
| Find out whether this hostname is an internationalized internet domain name (it has at least one label that has at least one UTF8/punycode character).
|
|
std::string | label (const int index=0, const int flags=rlabel::HOSTNAME_DEFAULT) |
| Extract a specific label from the underlying hostname.
|
|
uint | labels () |
| Find out how many labels the underlying hostname is comprised of.
|
|
rhostname * | set (const char *hostname, size_t len=0, const int flags=rlabel::HOSTNAME_DEFAULT) |
| Replace this rhostname's underlying hostname with a new hostname.
|
|
rhostname * | set (const std::string hostname, const int flags=rlabel::HOSTNAME_DEFAULT) |
| Replace this rhostname's underlying hostname with a new hostname.
|
|
std::string | to_dns_rr () |
| Convert the underlying hostname to a DNS RR and return it as an std::string.
|
|
std::string | to_string (const int flags=rlabel::HOSTNAME_DEFAULT) noexcept |
| Return as an std::string the hostname that this rhostname represents.
|
|
std::string | to_utf8 () |
| Convert the underlying hostname to UTF-8 and return it as an std::string.
|
|
std::string | to_xn () |
| Convert the underlying hostname to punycode and return it as an std::string.
|
|
This rhostname class provides an object-oriented internet hostname.
- Features
Some of the key features are:
- constructors with sensible defaults help to simplify coding
- documentation includes code samples (with
#include
lines as needed)
- thread-safety is noted where it is absolutely available (or where some caution is warranted)
- can handle ASCIIZ (C-strings) without needing to specify string length
- can handle
std::string
(which tracks its own string length)
- Use case
Validation of the format of a hostname from a variety of angles is helpful in ensuring that hostnames received from elsewhere comply with internet standards.
- Background
I created this class to make it easier to write internet server daemons. I also use it in my rmailaddr class when extracting the domain-part
.
- Getting started
- Author
- Randolf Richardson
- Version
- 1.00
- History
- 2023-Jan-17 v1.00 Initial version
- Conventions
- Lower-case letter "h" is regularly used in partial example code to represent an instantiated rhostname object.
An ASCIIZ string is a C-string (char* array) that includes a terminating null (0) character at the end.
- Notes
I use the term "ASCIIZ string" to indicate an array of characters that's terminated by a 0 (a.k.a., null). Although this is very much the same as a C-string, the difference is that in many API functions a C-string must often be accompanied by its length value. When referring to an ASCIIZ string, I'm intentionally indicating that the length of the string is not needed because the string is null-terminated. (This term was also commonly used in assembly language programming in the 1970s, 1980s, and 1990s, and as far as I know is still used by machine language programmers today.)
- Examples
#include <iostream>
#include <stdexcept>
#include <randolf/rhostname>
int main(int argc, char *argv[]) {
try {
} catch (const std::invalid_argument e) {
std::cerr << "Hostname format exception: " << e.what() << std::endl;
return EXIT_FAILURE;
} catch (const std::exception e) {
std::cerr << "Other exception: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
This rhostname class provides an object-oriented internet hostname.
Definition rhostname:109
Parameter stacking is supported (with methods that return rhostname*
); in this example, notice that semicolons (";") and "h." references are omittted (when compared with the above):
#include <iostream>
#include <stdexcept>
#include <randolf/rhostname>
int main(int argc, char *argv[]) {
try {
} catch (const std::invalid_argument e) {
std::cerr << "Hostname format exception: " << e.what() << std::endl;
return EXIT_FAILURE;
} catch (const std::exception e) {
std::cerr << "Other exception: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}