{
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;
+}
};
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,
};
/**
*/
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