+++ /dev/null
-/*
- * Copyright (c) 2009 Christopher L. Mikkelson <chris@mikk.net>
- * All Rights Reserved, for now.
- */
-
-#include <pcre.h>
-#include "re_stream.h"
-
-#include "msgproc.h"
-
-static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+";
-static pcre *html_url_re;
-
-static void
-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 */
- }
-}
-
-static void
-html_start(msgproc *m)
-{
- struct stream_re *s = malloc(sizeof(struct stream_re));
- re_stream_start(s, html_url_re, 0);
- msgproc_setpriv(m, (void *)s);
-}
-
-static void
-html_process(msgproc *m, char *buf, size_t size)
-{
- struct stream_re *sr = (struct stream_re *)msgproc_getpriv(m);
- int n;
-
- while (size > 0) {
- n = re_stream_exec(sr, buf, size);
- if (re_stream_result(sr) == 1) {
- char *url = re_stream_getresult(sr);
- if (m->callback)
- m->callback(m, url, m->call_data);
- }
- size -= n;
- buf += n;
- }
-}
-
-static void
-html_finish(msgproc *m)
-{
- struct stream_re *sr = (struct stream_re *)msgproc_getpriv(m);
- if (sr) {
- re_stream_stop(sr);
- free(sr);
- }
- msgproc_free(m);
-}
-
-msgproc_module msgproc_html = {
- MSGPROC_HTML, /* type */
- html_init, /* module init */
- NULL, /* set module parameter */
- html_start, /* start module instance */
- NULL, /* set module instance parameter */
- html_process, /* process data */
- html_finish, /* shut down, free module instance */
- NULL /* shut down, free module */
-};
static const char *text_url_pattern = "https?://\\S+";
static pcre *text_url_re;
+static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+";
+static pcre *html_url_re;
static void
-text_init(void) {
+text_plain_init(void) {
const char *etxt; int epos;
text_url_re = pcre_compile(text_url_pattern, 0, &etxt, &epos, 0);
if (!text_url_re) {
}
static void
-text_start(msgproc *m)
+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 */
+ }
+}
+
+static void
+text_plain_start(msgproc *m)
+{
+ struct stream_re *s = malloc(sizeof(struct stream_re));
+ re_stream_start(s, text_url_re, 0);
+ msgproc_setpriv(m, (void *)s);
+}
+
+static void
+text_html_start(msgproc *m)
{
struct stream_re *s = malloc(sizeof(struct stream_re));
re_stream_start(s, text_url_re, 0);
msgproc_module msgproc_text = {
MSGPROC_TEXT, /* type */
- text_init, /* module init */
+ text_plain_init, /* module init */
+ NULL, /* set module parameter */
+ text_plain_start, /* start module instance */
+ NULL, /* set module instance parameter */
+ text_process, /* process data */
+ text_finish, /* shut down, free module instance */
+ NULL /* shut down, free module */
+};
+
+msgproc_module msgproc_html = {
+ MSGPROC_HTML, /* type */
+ text_html_init, /* module init */
NULL, /* set module parameter */
- text_start, /* start module instance */
+ text_html_start, /* start module instance */
NULL, /* set module instance parameter */
text_process, /* process data */
text_finish, /* shut down, free module instance */