mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-24 14:30:18 +00:00
Add clickable emails + irc/ircs URLs
This commit is contained in:
@@ -35,11 +35,13 @@ GTree *url_btree = NULL;
|
|||||||
static gboolean regex_match (const GRegex *re, const char *word,
|
static gboolean regex_match (const GRegex *re, const char *word,
|
||||||
int *start, int *end);
|
int *start, int *end);
|
||||||
static const GRegex *re_url (void);
|
static const GRegex *re_url (void);
|
||||||
|
static const GRegex *re_email (void);
|
||||||
static const GRegex *re_nick (void);
|
static const GRegex *re_nick (void);
|
||||||
static const GRegex *re_channel (void);
|
static const GRegex *re_channel (void);
|
||||||
static gboolean match_nick (const char *word, int *start, int *end);
|
static gboolean match_nick (const char *word, int *start, int *end);
|
||||||
static gboolean match_channel (const char *word, int *start, int *end);
|
static gboolean match_channel (const char *word, int *start, int *end);
|
||||||
static gboolean match_url (const char *word, int *start, int *end);
|
static gboolean match_url (const char *word, int *start, int *end);
|
||||||
|
static gboolean match_email (const char *word, int *start, int *end);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
url_free (char *url, void *data)
|
url_free (char *url, void *data)
|
||||||
@@ -107,12 +109,18 @@ url_add (char *urltext, int len)
|
|||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
int size;
|
int size;
|
||||||
|
GUri *parsed;
|
||||||
|
|
||||||
if (!prefs.hex_url_grabber && !prefs.hex_url_logging)
|
if (!prefs.hex_url_grabber && !prefs.hex_url_logging)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (len <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data = g_strndup (urltext, len);
|
data = g_strndup (urltext, len);
|
||||||
|
|
||||||
if (data[len - 1] == '.')
|
if (data[len - 1] == '.')
|
||||||
@@ -125,6 +133,16 @@ url_add (char *urltext, int len)
|
|||||||
data[len - 1] = 0;
|
data[len - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parsed = g_uri_parse (data, G_URI_FLAGS_NONE, NULL);
|
||||||
|
if (parsed == NULL || g_uri_get_host (parsed) == NULL || *g_uri_get_host (parsed) == '\0')
|
||||||
|
{
|
||||||
|
if (parsed)
|
||||||
|
g_uri_unref (parsed);
|
||||||
|
g_free (data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_uri_unref (parsed);
|
||||||
|
|
||||||
if (prefs.hex_url_logging)
|
if (prefs.hex_url_logging)
|
||||||
{
|
{
|
||||||
url_save_node (data);
|
url_save_node (data);
|
||||||
@@ -182,6 +200,7 @@ url_check_word (const char *word)
|
|||||||
int type;
|
int type;
|
||||||
} m[] = {
|
} m[] = {
|
||||||
{ match_url, WORD_URL },
|
{ match_url, WORD_URL },
|
||||||
|
{ match_email, WORD_EMAIL },
|
||||||
{ match_channel, WORD_CHANNEL },
|
{ match_channel, WORD_CHANNEL },
|
||||||
{ match_nick, WORD_NICK },
|
{ match_nick, WORD_NICK },
|
||||||
{ NULL, 0}
|
{ NULL, 0}
|
||||||
@@ -261,6 +280,12 @@ match_url (const char *word, int *start, int *end)
|
|||||||
return regex_match (re_url (), word, start, end);
|
return regex_match (re_url (), word, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
match_email (const char *word, int *start, int *end)
|
||||||
|
{
|
||||||
|
return regex_match (re_email (), word, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
/* List of IRC commands for which contents (and thus possible URLs)
|
/* List of IRC commands for which contents (and thus possible URLs)
|
||||||
* are visible to the user. NOTE: Trailing blank required in each. */
|
* are visible to the user. NOTE: Trailing blank required in each. */
|
||||||
static char *commands[] = {
|
static char *commands[] = {
|
||||||
@@ -425,6 +450,8 @@ struct
|
|||||||
{ "ftp" },
|
{ "ftp" },
|
||||||
{ "gopher" },
|
{ "gopher" },
|
||||||
{ "gemini" },
|
{ "gemini" },
|
||||||
|
{ "irc" },
|
||||||
|
{ "ircs" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -461,6 +488,22 @@ re_url (void)
|
|||||||
return url_ret;
|
return url_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define EMAIL_LOCAL_ATOM "[\\pL\\pN!#$%&'*+/=?^_`{|}~-]+"
|
||||||
|
#define EMAIL_LOCAL EMAIL_LOCAL_ATOM "(\\." EMAIL_LOCAL_ATOM ")*"
|
||||||
|
#define EMAIL EMAIL_LOCAL "@" DOMAIN TLD
|
||||||
|
|
||||||
|
static const GRegex *
|
||||||
|
re_email (void)
|
||||||
|
{
|
||||||
|
static GRegex *email_ret;
|
||||||
|
|
||||||
|
if (email_ret) return email_ret;
|
||||||
|
|
||||||
|
email_ret = make_re ("(" EMAIL ")");
|
||||||
|
|
||||||
|
return email_ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* NICK description --- */
|
/* NICK description --- */
|
||||||
/* For NICKPRE see before url_check_word() */
|
/* For NICKPRE see before url_check_word() */
|
||||||
#define NICKHYP "-"
|
#define NICKHYP "-"
|
||||||
|
|||||||
Reference in New Issue
Block a user