ELinks 0.18.0
match-hostname.c File Reference
#include "elinks.h"
#include "intl/charsets.h"
#include "network/ssl/match-hostname.h"
#include "util/conv.h"
#include "util/error.h"
#include "util/string.h"
Include dependency graph for match-hostname.c:

Functions

int match_hostname_pattern (const char *hostname, size_t hostname_length, const char *pattern, size_t pattern_length)
 Checks whether a host name matches a pattern that may contain wildcards.

Function Documentation

◆ match_hostname_pattern()

int match_hostname_pattern ( const char * hostname,
size_t hostname_length,
const char * pattern,
size_t pattern_length )

Checks whether a host name matches a pattern that may contain wildcards.

Parameters
[in]hostnameThe host name to which the user wanted to connect. Should be in UTF-8 and need not be null-terminated.
[in]hostname_lengthThe length of hostname, in bytes.
[in]patternA pattern that the host name might match. Should be in UTF-8 and need not be null-terminated. The pattern may contain wildcards, as specified in RFC 2818 section 3.1.
[in]pattern_lengthThe length of pattern, in bytes.
Returns
Nonzero if the host name matches. Zero if it doesn't.

According to RFC 2818 section 3.1, '' matches any number of characters except '.'. For example, "*r</em>.example.org" matches "random.example.org" or "history.example.org" but not "frozen.fruit.example.org".

This function does not allocate memory, and consumes at most O(hostname_length * pattern_length) time.