*/
#include <pcre.h>
+#include <err.h>
#include "re_stream.h"
#include "msgproc.h"
-static const char *text_url_pattern = "https?://\\S+";
+static const char *text_url_pattern = "https?://[^\\s]+(?=\\s|$|\\))";
static pcre *text_url_re;
-static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+";
+static const char *html_url_pattern = "(?<=<a href=\")https?://[^\"]+(?=\")";
static pcre *html_url_re;
static void
-text_plain_init(void) {
+text_init(void) {
const char *etxt; int epos;
+ static int initialized = 0;
+
+ if (initialized) return;
+ initialized = 1;
+
text_url_re = pcre_compile(text_url_pattern, 0, &etxt, &epos, 0);
if (!text_url_re) {
- /* die */
+ errx(1, "text_url_pattern compile error\n");
}
-}
-
-static void
-text_html_init(void) {
- const char *etxt; int epos;
html_url_re = pcre_compile(html_url_pattern, 0, &etxt, &epos, 0);
if (!html_url_re) {
- /* die */
+ errx(1, "html_url_pattern compile error\n");
}
}
msgproc_module msgproc_text = {
MSGPROC_TEXT, /* type */
- text_plain_init, /* module init */
+ text_init, /* module init */
NULL, /* set module parameter */
text_plain_start, /* start module instance */
NULL, /* set module instance parameter */
msgproc_module msgproc_html = {
MSGPROC_HTML, /* type */
- text_html_init, /* module init */
+ text_init, /* module init */
NULL, /* set module parameter */
text_html_start, /* start module instance */
NULL, /* set module instance parameter */