mirror of
https://github.com/rfc1036/whois.git
synced 2026-05-03 06:51:09 +00:00
Rename domcmp() in endstrcaseeq() and rewrite it
Rewrite it to use the same code of in_domain().
This commit is contained in:
parent
8ccab2cb13
commit
db5dc4db7a
28
whois.c
28
whois.c
@ -442,7 +442,7 @@ const char *match_config_file(const char *s)
|
|||||||
}
|
}
|
||||||
regfree(&re);
|
regfree(&re);
|
||||||
#else
|
#else
|
||||||
if (domcmp(s, pattern)) {
|
if (endstrcaseeq(s, pattern)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return strdup(server);
|
return strdup(server);
|
||||||
}
|
}
|
||||||
@ -553,7 +553,7 @@ char *guess_server(const char *s)
|
|||||||
|
|
||||||
/* search for strings at the end of the word */
|
/* search for strings at the end of the word */
|
||||||
for (i = 0; nic_handles_post[i]; i += 2)
|
for (i = 0; nic_handles_post[i]; i += 2)
|
||||||
if (domcmp(s, nic_handles_post[i]))
|
if (endstrcaseeq(s, nic_handles_post[i]))
|
||||||
return strdup(nic_handles_post[i + 1]);
|
return strdup(nic_handles_post[i + 1]);
|
||||||
|
|
||||||
/* it's probably a network name */
|
/* it's probably a network name */
|
||||||
@ -1050,18 +1050,24 @@ int japanese_locale(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if dom ends with tld */
|
/* check if dom ends with tld */
|
||||||
int domcmp(const char *dom, const char *tld)
|
int endstrcaseeq(const char *dom, const char *tld)
|
||||||
{
|
{
|
||||||
const char *p, *q;
|
size_t dom_len, tld_len;
|
||||||
|
const char *p = NULL;
|
||||||
|
|
||||||
for (p = dom; *p; p++); p--; /* move to the last char */
|
if ((dom_len = strlen(dom)) == 0)
|
||||||
for (q = tld; *q; q++); q--;
|
|
||||||
while (p >= dom && q >= tld && tolower(*p) == *q) { /* compare backwards */
|
|
||||||
if (q == tld) /* start of the second word? */
|
|
||||||
return 1;
|
|
||||||
p--; q--;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if ((tld_len = strlen(tld)) == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* dom cannot be shorter than what we are looking for */
|
||||||
|
if (tld_len > dom_len)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
p = dom + dom_len - tld_len;
|
||||||
|
|
||||||
|
return strcaseeq(p, tld);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if dom is a subdomain of tld */
|
/* check if dom is a subdomain of tld */
|
||||||
|
|||||||
2
whois.h
2
whois.h
@ -28,7 +28,7 @@ int japanese_locale(void);
|
|||||||
unsigned long myinet_aton(const char *);
|
unsigned long myinet_aton(const char *);
|
||||||
unsigned long asn32_to_long(const char *);
|
unsigned long asn32_to_long(const char *);
|
||||||
int isasciidigit(const char);
|
int isasciidigit(const char);
|
||||||
int domcmp(const char *, const char *);
|
int endstrcaseeq(const char *, const char *);
|
||||||
int in_domain(const char *, const char *);
|
int in_domain(const char *, const char *);
|
||||||
const char *is_new_gtld(const char *);
|
const char *is_new_gtld(const char *);
|
||||||
int domfind(const char *, const char *[]);
|
int domfind(const char *, const char *[]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user