- freez(url->dbuf);
- freez(url->dvec);
- return(fwd_default);
-
-}
-
-
-/*********************************************************************
- *
- * Function : dsplit
- *
- * Description : Takes a domain and returns a pointer to a url_spec
- * structure populated with dbuf, dcnt and dvec. The
- * other fields in the structure that is returned are zero.
- *
- * Parameters :
- * 1 : domain = a URL address
- *
- * Returns : url_spec structure populated with dbuf, dcnt and dvec.
- *
- *********************************************************************/
-struct url_spec dsplit(char *domain)
-{
- struct url_spec ret[1];
- char *v[BUFFER_SIZE];
- int size;
- char *p;
-
- memset(ret, '\0', sizeof(*ret));
-
- if (domain[strlen(domain) - 1] == '.')
- {
- ret->unanchored |= ANCHOR_RIGHT;
- }
-
- if (domain[0] == '.')
- {
- ret->unanchored |= ANCHOR_LEFT;
- }
-
- ret->dbuf = strdup(domain);
-
- /* map to lower case */
- for (p = ret->dbuf; *p ; p++) *p = tolower(*p);
-
- /* split the domain name into components */
- ret->dcnt = ssplit(ret->dbuf, ".", v, SZ(v), 1, 1);
-
- if (ret->dcnt <= 0)
- {
- memset(ret, '\0', sizeof(ret));
- return(*ret);
- }
-
- /* save a copy of the pointers in dvec */
- size = ret->dcnt * sizeof(*ret->dvec);
-
- if ((ret->dvec = (char **)malloc(size)))
- {
- memcpy(ret->dvec, v, size);
- }
-
- return(*ret);
-
-}
-
-
-/*********************************************************************
- *
- * Function : simple_domaincmp
- *
- * Description : Domain-wise Compare fqdn's. The comparison is
- * both left- and right-anchored. The individual
- * domain names are compared with simplematch().
- * This is only used by domaincmp.
- *
- * Parameters :
- * 1 : pv = array of patterns to compare
- * 2 : fv = array of domain components to compare
- * 3 : len = length of the arrays (both arrays are the
- * same length - if they weren't, it couldn't
- * possibly be a match).
- *
- * Returns : 0 => domains are equivalent, else no match.
- *
- *********************************************************************/
-static int simple_domaincmp(char **pv, char **fv, int len)
-{
- int n;
-
- for (n = 0; n < len; n++)
- {
- if (simplematch(pv[n], fv[n]))
- {
- return 1;
- }
- }
-
- return 0;
-
-}
-
-
-/*********************************************************************
- *
- * Function : domaincmp
- *
- * Description : Domain-wise Compare fqdn's. Governed by the bimap in
- * pattern->unachored, the comparison is un-, left-,
- * right-anchored, or both.
- * The individual domain names are compared with
- * simplematch().
- *
- * Parameters :
- * 1 : pattern = a domain that may contain a '*' as a wildcard.
- * 2 : fqdn = domain name against which the patterns are compared.
- *
- * Returns : 0 => domains are equivalent, else no match.
- *
- *********************************************************************/
-int domaincmp(struct url_spec *pattern, struct url_spec *fqdn)
-{
- char **pv, **fv; /* vectors */
- int plen, flen;
- int unanchored = pattern->unanchored & (ANCHOR_RIGHT | ANCHOR_LEFT);
-
- plen = pattern->dcnt;
- flen = fqdn->dcnt;
-
- if (flen < plen)
- {
- /* fqdn is too short to match this pattern */
- return 1;
- }
-
- pv = pattern->dvec;
- fv = fqdn->dvec;
-
- if (unanchored == ANCHOR_LEFT)
- {
- /*
- * Right anchored.
- *
- * Convert this into a fully anchored pattern with
- * the fqdn and pattern the same length
- */
- fv += (flen - plen); /* flen - plen >= 0 due to check above */
- return simple_domaincmp(pv, fv, plen);
- }
- else if (unanchored == 0)
- {
- /* Fully anchored, check length */
- if (flen != plen)
- {
- return 1;
- }
- return simple_domaincmp(pv, fv, plen);
- }
- else if (unanchored == ANCHOR_RIGHT)
- {
- /* Left anchored, ignore all extra in fqdn */
- return simple_domaincmp(pv, fv, plen);
- }
- else
- {
- /* Unanchored */
- int n;
- int maxn = flen - plen;
- for (n = 0; n <= maxn; n++)
- {
- if (!simple_domaincmp(pv, fv, plen))
- {
- return 0;
- }
- /*
- * Doesn't match from start of fqdn
- * Try skipping first part of fqdn
- */
- fv++;
- }
- return 1;
- }
-