]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add functions to deal with url protocols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 16 Feb 2019 13:52:55 +0000 (13:52 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 16 Feb 2019 13:52:55 +0000 (13:52 +0000)
src/libserver/url.c
src/libserver/url.h

index 461c232af1d5ef60ebaf782b237ad3c9905f0a74..ae2f84300cbbfe8bb90a3758928975ffee83bd51 100644 (file)
@@ -3330,3 +3330,61 @@ rspamd_url_is_domain (int c)
 {
        return is_domain ((guchar)c);
 }
+
+const gchar*
+rspamd_url_protocol_name (enum rspamd_url_protocol proto)
+{
+       const gchar *ret = "unknown";
+
+       switch (proto) {
+       case PROTOCOL_HTTP:
+               ret = "http";
+               break;
+       case PROTOCOL_HTTPS:
+               ret = "https";
+               break;
+       case PROTOCOL_FTP:
+               ret = "ftp";
+               break;
+       case PROTOCOL_FILE:
+               ret = "file";
+               break;
+       case PROTOCOL_MAILTO:
+               ret = "mailto";
+               break;
+       case PROTOCOL_TELEPHONE:
+               ret = "telephone";
+               break;
+       default:
+               break;
+       }
+
+       return ret;
+}
+
+enum rspamd_url_protocol
+rspamd_url_protocol_from_string (const gchar *str)
+{
+       enum rspamd_url_protocol ret = PROTOCOL_UNKNOWN;
+
+       if (strcmp (str, "http") == 0) {
+               ret = PROTOCOL_HTTP;
+       }
+       else if (strcmp (str, "https") == 0) {
+               ret = PROTOCOL_HTTPS;
+       }
+       else if (strcmp (str, "mailto") == 0) {
+               ret = PROTOCOL_MAILTO;
+       }
+       else if (strcmp (str, "ftp") == 0) {
+               ret = PROTOCOL_FTP;
+       }
+       else if (strcmp (str, "file") == 0) {
+               ret = PROTOCOL_FILE;
+       }
+       else if (strcmp (str, "telephone") == 0) {
+               ret = PROTOCOL_TELEPHONE;
+       }
+
+       return ret;
+}
index 4c34be9e7c88ca5f014388afab1eaa0e8e3cd54b..4d19489212046a11771abb0990ffa785da7320c9 100644 (file)
@@ -79,13 +79,13 @@ enum uri_errno {
 };
 
 enum rspamd_url_protocol {
-       PROTOCOL_FILE = 0,
-       PROTOCOL_FTP,
-       PROTOCOL_HTTP,
-       PROTOCOL_HTTPS,
-       PROTOCOL_MAILTO,
-       PROTOCOL_TELEPHONE,
-       PROTOCOL_UNKNOWN
+       PROTOCOL_FILE = 1u << 0,
+       PROTOCOL_FTP = 1u << 1,
+       PROTOCOL_HTTP = 1u << 2,
+       PROTOCOL_HTTPS = 1u << 3,
+       PROTOCOL_MAILTO = 1u << 4,
+       PROTOCOL_TELEPHONE = 1u << 5,
+       PROTOCOL_UNKNOWN = -1,
 };
 
 /**
@@ -240,4 +240,18 @@ const gchar * rspamd_url_encode (struct rspamd_url *url, gsize *dlen,
  */
 gboolean rspamd_url_is_domain (int c);
 
+/**
+ * Returns symbolic name for protocol
+ * @param proto
+ * @return
+ */
+const gchar* rspamd_url_protocol_name (enum rspamd_url_protocol proto);
+
+
+/**
+ * Converts string to a numeric protocol
+ * @param str
+ * @return
+ */
+enum rspamd_url_protocol rspamd_url_protocol_from_string (const gchar *str);
 #endif