summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-10-25 16:55:37 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-10-25 16:55:37 +0300
commit08f69cc36908f376659369a3c5ee2f63a75f1c73 (patch)
treec5789dc5353dc70d1bb649144a6ac639fb33798c
parenteb3a07ec466ebc923230618d059bdb4c29b170b9 (diff)
downloadmailutils-08f69cc36908f376659369a3c5ee2f63a75f1c73.tar.gz
mailutils-08f69cc36908f376659369a3c5ee2f63a75f1c73.tar.bz2
Improve URL matching code.
* libmailutils/base/url.c (mu_url_matches_ticket): Use different weight values, depending on the missing part. * libmailutils/base/wicket.c (mu_wicket_stream_match_url): Refuse URLs that lack host and password parts.
-rw-r--r--libmailutils/base/url.c21
-rw-r--r--libmailutils/base/wicket.c8
2 files changed, 21 insertions, 8 deletions
diff --git a/libmailutils/base/url.c b/libmailutils/base/url.c
index 49aab4b18..96345f056 100644
--- a/libmailutils/base/url.c
+++ b/libmailutils/base/url.c
@@ -966,20 +966,25 @@ mu_url_decode (const char *s)
#define is_wildcard(s) ((s)[0] == '*' && s[1] == 0)
+#define WEIGHT_SCHEME 3
+#define WEIGHT_USER 4
+#define WEIGHT_HOST 2
+#define WEIGHT_PORT 1
+
int
mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *pwc)
{
int wcnt = 0;
-
+
if (is_wildcard (ticket->scheme))
- wcnt++;
+ wcnt += WEIGHT_SCHEME;
else if (mu_c_strcasecmp (ticket->scheme, url->scheme))
return 0;
if (ticket->flags & MU_URL_HOST)
{
if (is_wildcard (ticket->host))
- wcnt++;
+ wcnt += WEIGHT_HOST;
else if (url->flags & MU_URL_HOST)
{
if (mu_c_strcasecmp (ticket->host, url->host))
@@ -990,7 +995,7 @@ mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *pwc)
return 0;
}
else
- wcnt++;
+ wcnt += WEIGHT_HOST;
if (ticket->flags & MU_URL_PORT)
{
@@ -1000,16 +1005,16 @@ mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *pwc)
if (ticket->port != url->port)
return 0;
else
- wcnt++;
+ wcnt += WEIGHT_PORT;
}
}
else
- wcnt++;
+ wcnt += WEIGHT_PORT;
if (ticket->flags & MU_URL_USER)
{
if (is_wildcard (ticket->user))
- wcnt += 2;
+ wcnt += WEIGHT_USER;
/* If ticket has a user or pass, but url doesn't, that's OK, we were
looking for this info. But if url does have a user/pass, it
@@ -1021,7 +1026,7 @@ mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *pwc)
}
}
else
- wcnt++;
+ wcnt += WEIGHT_USER;
/* Guess it matches. */
if (pwc)
diff --git a/libmailutils/base/wicket.c b/libmailutils/base/wicket.c
index 4d79c2ce4..3e808c0ea 100644
--- a/libmailutils/base/wicket.c
+++ b/libmailutils/base/wicket.c
@@ -284,6 +284,14 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
mu_url_destroy (&u);
continue;
}
+
+ if (!mu_url_has_flag (u, MU_URL_USER|MU_URL_SECRET))
+ {
+ mu_error (_("%s:%u: URL is missing required parts"),
+ loc->file, loc->line);
+ mu_url_destroy (&u);
+ continue;
+ }
if (!mu_url_matches_ticket (u, url, &n))
{

Return to:

Send suggestions and report system problems to the System administrator.