commit e42a7c2: [Minor] Add urls compare method
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Feb 22 16:14:06 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-02-22 15:04:21 +0000
URL: https://github.com/rspamd/rspamd/commit/e42a7c204a62c66eaa5da3f71d216c48e92a355a
[Minor] Add urls compare method
---
src/libserver/url.c | 35 +++++++++++++++++++++++++++++++++++
src/libserver/url.h | 8 ++++++++
2 files changed, 43 insertions(+)
diff --git a/src/libserver/url.c b/src/libserver/url.c
index 73daf043a..f64fba135 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -4166,3 +4166,38 @@ rspamd_url_flag_to_string (int flag)
return NULL;
}
+
+int
+rspamd_url_cmp (const struct rspamd_url *u1, const struct rspamd_url *u2)
+{
+ if (u1->protocol != u2->protocol || u1->urllen != u2->urllen) {
+ if (u1->protocol != u2->protocol) {
+ return u1->protocol < u2->protocol;
+ }
+
+ return (int)u1->urllen - (int)u2->urllen;
+ }
+ else {
+ int r;
+
+ if (u1->protocol & PROTOCOL_MAILTO) {
+ if ((r = rspamd_lc_cmp (rspamd_url_host_unsafe (u1),
+ rspamd_url_host_unsafe (u2), u1->hostlen)) == 0) {
+ if (u1->userlen != u2->userlen || u1->userlen == 0) {
+ return (int)u1->userlen - (int)u2->userlen;
+ }
+ else {
+ return rspamd_lc_cmp (rspamd_url_user_unsafe(u1),
+ rspamd_url_user_unsafe(u2),
+ u1->userlen);
+ }
+ }
+
+ return r;
+ }
+
+ r = memcmp (u1->string, u2->string, u1->urllen);
+
+ return r;
+ }
+}
\ No newline at end of file
diff --git a/src/libserver/url.h b/src/libserver/url.h
index 7fddd07ef..ca111ecf1 100644
--- a/src/libserver/url.h
+++ b/src/libserver/url.h
@@ -324,6 +324,14 @@ bool rspamd_url_host_set_add (khash_t (rspamd_url_host_hash) *set,
bool rspamd_url_set_has (khash_t (rspamd_url_hash) *set, struct rspamd_url *u);
bool rspamd_url_host_set_has (khash_t (rspamd_url_host_hash) *set, struct rspamd_url *u);
+/**
+ * Compares two urls (similar to C comparison functions)
+ * @param u1
+ * @param u2
+ * @return
+ */
+int rspamd_url_cmp (const struct rspamd_url *u1, const struct rspamd_url *u2);
+
#ifdef __cplusplus
}
#endif
More information about the Commits
mailing list